-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
412 additions
and
674 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
set dotenv-load | ||
|
||
# variables | ||
module := "icarus.investments.dag" | ||
package := "icarus-cds" | ||
|
||
# aliases | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,57 @@ | ||
import os | ||
import ibis | ||
|
||
from icarus.config import DATA_DIR | ||
from icarus.config import CLOUD, BUCKET, DATA_DIR | ||
|
||
|
||
# define data catalog | ||
class Catalog: | ||
def __init__(self, data_dir=DATA_DIR): | ||
self.data_dir = data_dir | ||
# functions | ||
def delta_table_path(table_name: str) -> str: | ||
return os.path.join(DATA_DIR, f"{table_name}.delta") | ||
|
||
|
||
def read_table(table_name: str) -> ibis.Table: | ||
if CLOUD: | ||
import gcsfs | ||
|
||
fs = gcsfs.GCSFileSystem() | ||
ibis.get_backend().register_filesystem(fs) | ||
|
||
table_path = f"gs://{BUCKET}/{delta_table_path(table_name)}" | ||
else: | ||
table_path = delta_table_path(table_name) | ||
|
||
return ibis.read_delta(table_path) | ||
|
||
|
||
def list_groups(self): | ||
def write_table(t: ibis.Table, table_name: str) -> None: | ||
if CLOUD: | ||
import gcsfs | ||
|
||
fs = gcsfs.GCSFileSystem() | ||
ibis.get_backend().register_filesystem(fs) | ||
|
||
table_path = f"gs://{BUCKET}/{delta_table_path(table_name)}" | ||
else: | ||
table_path = delta_table_path(table_name) | ||
|
||
t.to_delta( | ||
table_path, | ||
mode="overwrite", | ||
partition_by=["extracted_at"], | ||
) | ||
|
||
|
||
# classes | ||
class Catalog: | ||
def list_tables(self): | ||
return [ | ||
d | ||
for d in os.listdir(self.data_dir) | ||
for d in os.listdir(DATA_DIR) | ||
if not (d.startswith("_") or d.startswith(".")) | ||
] | ||
|
||
def list_tables(self, group): | ||
return [d.split(".")[0] for d in os.listdir(os.path.join(self.data_dir, group))] | ||
def table(self, table_name): | ||
return read_table(table_name) | ||
|
||
def table(self, table_name, group_name=None): | ||
if group_name is None: | ||
group_name = table_name.split("_")[0].upper() | ||
return ibis.read_delta(f"{DATA_DIR}/{group_name}/{table_name}.delta") | ||
def write_table(self, t, table_name): | ||
write_table(t, table_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
# configuration file for the data DAG | ||
DAG_MODULE = "icarus.investments.dag" | ||
|
||
CLOUD = False | ||
BUCKET = "icarus" | ||
BUCKET = "icarus-datalake" | ||
|
||
DATA_DIR = "datalake" | ||
RAW_DATA_DIR = "_raw" | ||
RAW_BUY_SELL_TABLE = "buy_sell" | ||
RAW_SOCIAL_MEDIA_TABLE = "social_media" | ||
|
||
BRONZE = "bronze" | ||
SILVER = "silver" | ||
GOLD = "gold" | ||
BUY_SELL_TABLE = "buy_sell" | ||
SOCIAL_MEDIA_TABLE = "social_media" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.