Axel Waserman
03/06/2024, 6:17 PMScout
03/06/2024, 6:17 PMDailyPartitionsDefinition
along with a TimeWindowPartitionMapping
. The TimeWindowPartitionMapping
allows you to specify offsets for the start and end of the partition window relative to the current partition. Here's an example of how you might define such an asset: python from dagster import asset, DailyPartitionsDefinition, TimeWindowPartitionMapping, AssetIn partitions_def = DailyPartitionsDefinition(start_date="2023-01-01") @asset( partitions_def=partitions_def, ins={ "my_asset": AssetIn( partition_mapping=TimeWindowPartitionMapping( start_offset=-7, # Start from 7 days before the current partition end_offset=-1 # End at 1 day before the current partition ), ) }, ) def my_asset(): ...
In this example, the TimeWindowPartitionMapping
is configured with a start_offset
of -7 and an end_offset
of -1. This means that when the asset is materialized, it will, by default, include the partitions from the last 7 days up until yesterday. Please note that the actual implementation of the asset's computation will need to handle the logic for processing the data from the specified partition range. The TimeWindowPartitionMapping
only defines the default behavior for partition selection during materialization. Keep in mind that this example assumes that you have a corresponding upstream asset named my_asset
that is also partitioned daily. If your asset does not have dependencies, you can omit the ins
parameter and the AssetIn
definition.