Simon Ammer
02/12/2024, 2:22 PMlatest_materialization_records_by_partition_and_asset
can be used, please!Scout
02/12/2024, 2:22 PMlatest_materialization_records_by_partition_and_asset
method is used within a multi-asset sensor to find the most recent unconsumed materialization for each partition for each asset monitored by the sensor. It aggregates all materializations into a mapping of partition key to a mapping of asset key to the materialization event for that partition. Here's an example from the documentation: python from dagster import asset, multi_asset_sensor, DailyPartitionsDefinition @asset(partitions_def=DailyPartitionsDefinition("2022-07-01")) def july_asset(): return 1 @multi_asset_sensor(asset_keys=[july_asset.key]) def my_sensor(context): records = context.latest_materialization_records_by_partition(july_asset.key) # After materializing july_asset for 2022-07-05, latest_materialization_by_partition # returns {"2022-07-05": EventLogRecord(...)}
In this example, july_asset
is a partitioned asset with daily partitions starting from July 1st, 2022. The my_sensor
is a multi-asset sensor that monitors the july_asset
. When the sensor is evaluated, it uses the latest_materialization_records_by_partition
method to get the latest materialization records for the july_asset
by partition. If july_asset
was materialized for the partition corresponding to July 5th, 2022, the method would return a dictionary with the partition key "2022-07-05" and the associated EventLogRecord
for that materialization. This method is useful when you want to trigger downstream computations or checks based on the latest materialization of partitioned assets.