-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Noel Gomez
committed
Oct 21, 2024
1 parent
5804bab
commit b161238
Showing
8 changed files
with
192 additions
and
67 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import dlt | ||
|
||
def set_config_value(key, config_key, env_var_prefix = 'DATACOVES__MAIN_LOAD__'): | ||
|
||
env_var = env_var_prefix + key.upper() | ||
|
||
value = os.getenv(env_var, dlt.config[config_key]) | ||
|
||
if key != 'password': | ||
print(key + ": " +value) | ||
return value | ||
|
||
config_keys = ["account", "database", "warehouse", "role", "user", "password"] | ||
|
||
db_config = {} | ||
for key in config_keys: | ||
config_key = "destination.snowflake.credentials." + key | ||
|
||
try: | ||
dlt.config[config_key] | ||
except dlt.common.configuration.exceptions.ConfigFieldMissingException: | ||
dlt.config[config_key] = '' | ||
|
||
db_config[key] = set_config_value(key, config_key) | ||
|
||
# This is needed because by default dlt calls the snowflake account host | ||
db_config['host'] = db_config['account'] | ||
db_config['username'] = db_config['user'] |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env -S uv run --cache-dir /tmp/.uv_cache | ||
# /// script | ||
# dependencies = [ | ||
# "dlt[snowflake, parquet]==1.1.0", | ||
# "enlighten~=1.12.4", | ||
# "psutil~=6.0.0", | ||
# "pandas==2.2.2", | ||
# ] | ||
# /// | ||
"""Loads a CSV file to Snowflake""" | ||
import dlt | ||
import pandas as pd | ||
from datacoves_snowflake import db_config | ||
|
||
# a resource is the individual endpoints or tables | ||
@dlt.resource(write_disposition="replace") | ||
# method name = table name | ||
def personal_loans(): | ||
personal_loans = "https://datacoves-sample-data-public.s3.us-west-2.amazonaws.com/PERSONAL_LOANS.csv" | ||
df = pd.read_csv(personal_loans) | ||
yield df | ||
|
||
def zip_coordinates(): | ||
zip_coordinates = "https://datacoves-sample-data-public.s3.us-west-2.amazonaws.com/ZIP_COORDINATES.csv" | ||
df = pd.read_csv(zip_coordinates) | ||
yield df | ||
|
||
# Source (corresponds to API or database) | ||
@dlt.source | ||
def personal_loans_source(): | ||
return [personal_loans] | ||
|
||
@dlt.source | ||
def zip_coordinates_source(): | ||
return [zip_coordinates] | ||
|
||
if __name__ == "__main__": | ||
datacoves_snowflake = dlt.destinations.snowflake( | ||
db_config, | ||
destination_name="datacoves_snowflake" | ||
) | ||
|
||
pipeline = dlt.pipeline( | ||
progress = "enlighten", | ||
pipeline_name = "loans", | ||
destination = datacoves_snowflake, | ||
pipelines_dir = "/tmp/", | ||
|
||
# dataset_name is the target schema name | ||
dataset_name="loans" | ||
) | ||
|
||
load_info = pipeline.run(personal_loans()) | ||
|
||
print(load_info) | ||
|
||
load_info = pipeline.run(zip_coordinates()) | ||
|
||
print(load_info) |
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
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
6 changes: 3 additions & 3 deletions
6
transform/models/L3_coves/loan_analytics/loans_by_state__dynamic.sql
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
Oops, something went wrong.