I'm materializing two different assets from an op ...
# ask-community
c
I'm materializing two different assets from an op by running
AssetsDefinition.from_op()
twice. I need the op to process the received input slightly differently depending on a parameter. In the example below, what's the best way to pass a parameter to the
label_target
op to control its internal logic?
Copy code
labelled_brw = AssetsDefinition.from_op(
    label_target,
    keys_by_input_name={"df": AssetKey("merge_raw_p_attrition")},
    keys_by_output_name={"result": AssetKey("labelled_brw")},
    group_name="preprocessing",
)

labelled_tul = AssetsDefinition.from_op(
    label_target,
    keys_by_input_name={"df": AssetKey("merge_raw_tul_cais")},
    keys_by_output_name={"result": AssetKey("labelled_tul")},
    group_name="preprocessing_tul",
)
Update: I created the logic using the
result_asset
value from
result_asset = context.asset_key_for_output("result").to_string()
in the op. Works well though not sure it's the best/dagster approach.
c
If you want to fork the logic in the op, you could consider a couple other options: • Adding config to the op, and materializing the assets with config • Splitting the op implementation into 2 separate ops, and implementing the assets from there
🙏 1
c
Thanks, @claire. I saw the config approach in the docs here, but it wasn't clear how to specify which config to use when the op is called via
AssetsDefinition.from_op
c
How are you executing? If you are executing via Dagit, you can shift-click to specify run config. Otherwise, if you are yielding runs via
RunRequests
in a schedule or sensor, you can specify config on the
RunRequest