-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] [snowflake] Add partitions to snowflake guide (#12231)
- Loading branch information
1 parent
c251806
commit 532ced5
Showing
10 changed files
with
286 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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
48 changes: 48 additions & 0 deletions
48
examples/docs_snippets/docs_snippets/integrations/snowflake/multi_partition.py
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,48 @@ | ||
def get_iris_data_for_date(*args, **kwargs): | ||
pass | ||
|
||
|
||
# start_example | ||
|
||
import pandas as pd | ||
|
||
from dagster import ( | ||
DailyPartitionsDefinition, | ||
MultiPartitionsDefinition, | ||
StaticPartitionDefinition, | ||
asset, | ||
) | ||
|
||
|
||
@asset( | ||
partitions_def=MultiPartitionsDefinition( | ||
{ | ||
"date": DailyPartitionsDefinition(start_date="2023-01-01"), | ||
"species": StaticPartitionDefinition( | ||
["Iris-setosa", "Iris-virginica", "Iris-versicolor"] | ||
), | ||
} | ||
), | ||
metadata={ | ||
"partition_expr": {"date": "TO_TIMESTAMP(time::INT)", "species": "SPECIES"} | ||
}, | ||
) | ||
def iris_dataset_partitioned(context) -> pd.DataFrame: | ||
partition = partition = context.partition_key.keys_by_dimension | ||
species = partition["species"] | ||
date = partition["date"] | ||
|
||
# get_iris_data_for_date fetches all of the iris data for a given date, | ||
# the returned dataframe contains a column named 'time' with that stores | ||
# the time of the row as an integer of seconds since epoch | ||
full_df = get_iris_data_for_date(date) | ||
|
||
return full_df[full_df["Species"] == species] | ||
|
||
|
||
@asset | ||
def iris_cleaned(iris_dataset_partitioned: pd.DataFrame): | ||
return iris_dataset_partitioned.dropna().drop_duplicates() | ||
|
||
|
||
# end_example |
36 changes: 36 additions & 0 deletions
36
examples/docs_snippets/docs_snippets/integrations/snowflake/static_partition.py
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,36 @@ | ||
# start_example | ||
|
||
import pandas as pd | ||
|
||
from dagster import StaticPartitionDefinition, asset | ||
|
||
|
||
@asset( | ||
partitions_def=StaticPartitionDefinition( | ||
["Iris-setosa", "Iris-virginica", "Iris-versicolor"] | ||
), | ||
metadata={"partition_expr": "SPECIES"}, | ||
) | ||
def iris_dataset_partitioned(context) -> pd.DataFrame: | ||
species = context.asset_partition_key_for_output() | ||
|
||
full_df = pd.read_csv( | ||
"https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", | ||
names=[ | ||
"Sepal length (cm)", | ||
"Sepal width (cm)", | ||
"Petal length (cm)", | ||
"Petal width (cm)", | ||
"Species", | ||
], | ||
) | ||
|
||
return full_df[full_df["Species"] == species] | ||
|
||
|
||
@asset | ||
def iris_cleaned(iris_dataset_partitioned: pd.DataFrame): | ||
return iris_dataset_partitioned.dropna().drop_duplicates() | ||
|
||
|
||
# end_example |
30 changes: 30 additions & 0 deletions
30
examples/docs_snippets/docs_snippets/integrations/snowflake/time_partition.py
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,30 @@ | ||
def get_iris_data_for_date(*args, **kwargs): | ||
pass | ||
|
||
|
||
# start_example | ||
|
||
import pandas as pd | ||
|
||
from dagster import DailyPartitionsDefinition, asset | ||
|
||
|
||
@asset( | ||
partitions_def=DailyPartitionsDefinition(start_date="2023-01-01"), | ||
metadata={"partition_expr": "TO_TIMESTAMP(time::INT)"}, | ||
) | ||
def iris_data_per_day(context) -> pd.DataFrame: | ||
partition = context.asset_partition_key_for_output() | ||
|
||
# get_iris_data_for_date fetches all of the iris data for a given date, | ||
# the returned dataframe contains a column named 'time' with that stores | ||
# the time of the row as an integer of seconds since epoch | ||
return get_iris_data_for_date(partition) | ||
|
||
|
||
@asset | ||
def iris_cleaned(iris_data_per_day: pd.DataFrame): | ||
return iris_data_per_day.dropna().drop_duplicates() | ||
|
||
|
||
# end_example |
532ced5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dagster – ./docs/next
dagster.vercel.app
dagster-git-master-elementl.vercel.app
docs.dagster.io
dagster-elementl.vercel.app
new-docs.dagster.io