Paul Herzog
02/21/2024, 12:52 PMScout
02/21/2024, 12:52 PMMetadataValue
in Dagster would be to convert them into a JSON format using MetadataValue.json
. This method allows you to attach JSON-serializable data to your metadata, which can be easily used to represent lists or sets. Here's an example from the documentation on how to use `MetadataValue.json`: python @op def emit_metadata(context): my_list = [1, 2, 3] my_set = {"a", "b", "c"} yield AssetMaterialization( asset_key="my_dataset", metadata={ "my_list": MetadataValue.json(list(my_list)), # Convert set to list for JSON serialization "my_set": MetadataValue.json(list(my_set)) # Convert set to list for JSON serialization }, )
In this example, both the list and the set are converted to lists (since sets are not JSON serializable) and then passed to MetadataValue.json
to be included in the metadata. This way, you can preview the values in the Dagster UI or any other tooling that consumes this metadata.