https://dagster.io/ logo
#ask-community
Title
# ask-community
l

Luke Dziurzynski

08/06/2023, 10:55 PM
I'm very confused with dynamic partitions. I have one asset that returns a dataframe, and want to iterate over the values of that column to run at most one request for each unique value in that column. Currently I have:
Copy code
@asset
def users() -> pd.DataFrame:
    return pd.read_csv("./data/users.csv").head(4)

@asset_sensor(asset_key=AssetKey("users"))
def user_sensor(context: SensorEvaluationContext, asset_event: EventLogEntry):
    yield RunRequest(partition_key=asset_event.asset_materialization.metadata["partition_key"])
It is very unclear what I'm supposed to do next. I have been hopping around between documentation for sensors, asset sensors, @claire's slack messages, context.cursor, dynamic partitions, and the dynamic partitions example from github and am suuuuuper lost. What do I do next to run a function that receives that new dynamic partition value and writes an asset?
t

Tim Castillo

08/07/2023, 4:17 PM
Hi! Sorry the experience has you feeling this way, and I appreciate your feedback. Once you've yielded the run request, the assets the
users
asset will kick off a run and you can access the run's partition key with `
Copy code
context.asset_partition_key_for_output()
`, as you would with other partitioned assets. At that point, it's up to the user to decide what the logic is to use that information about the partition themselves. ie. using that key query a database or upsert a record somewhere.
2 Views