-
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.
Allow default io_manager load_input to support partitions of differin…
…g frequencies (#10172) * a working implementation * support backwards compatibility, add key value collection and type annotations * fix white space * tidy up partition filepath method to match existing methods * use make isort * rename method to make it clear and easy to find * fix test suite * remove unused imports * ran isort again after removing unused imports
- Loading branch information
1 parent
cf8ad4a
commit 58ee17c
Showing
2 changed files
with
89 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
...n_modules/dagster/dagster_tests/core_tests/partition_tests/test_partitioned_io_manager.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,62 @@ | ||
import datetime | ||
|
||
from pytest import fixture | ||
|
||
from dagster import DailyPartitionsDefinition, HourlyPartitionsDefinition, asset, materialize | ||
|
||
|
||
@fixture | ||
def start(): | ||
return datetime.datetime(2022, 1, 1) | ||
|
||
|
||
@fixture | ||
def hourly(start): | ||
return HourlyPartitionsDefinition(start_date=f"{start:%Y-%m-%d-%H:%M}") | ||
|
||
|
||
@fixture | ||
def daily(start): | ||
return DailyPartitionsDefinition(start_date=f"{start:%Y-%m-%d}") | ||
|
||
|
||
def test_partitioned_io_manager(hourly, daily): | ||
@asset(partitions_def=hourly) | ||
def hourly_asset(): | ||
return 42 | ||
|
||
@asset(partitions_def=daily) | ||
def daily_asset(hourly_asset): | ||
return hourly_asset | ||
|
||
# Build hourly materializations | ||
hourly_keys = [f"2022-01-01-{hour:02d}:00" for hour in range(0, 24)] | ||
for key in hourly_keys: | ||
materialize( | ||
[hourly_asset], | ||
partition_key=key, | ||
) | ||
|
||
# Materialize daily asset that depends on hourlies | ||
result = materialize( | ||
[*hourly_asset.to_source_assets(), daily_asset], | ||
partition_key="2022-01-01", | ||
) | ||
expected = {k: 42 for k in hourly_keys} | ||
assert result.output_for_node("daily_asset") == expected | ||
|
||
|
||
def test_partitioned_io_manager_preserves_single_partition_dependency(daily): | ||
@asset(partitions_def=daily) | ||
def upstream_asset(): | ||
return 42 | ||
|
||
@asset(partitions_def=daily) | ||
def daily_asset(upstream_asset): | ||
return upstream_asset | ||
|
||
result = materialize( | ||
[upstream_asset, daily_asset], | ||
partition_key="2022-01-01", | ||
) | ||
assert result.output_for_node("daily_asset") == 42 |