Differential D8684 Diff 40813 examples/docs_snippets/docs_snippets/concepts/configuration/configured_named_solid_example.py
Changeset View
Changeset View
Standalone View
Standalone View
examples/docs_snippets/docs_snippets/concepts/configuration/configured_named_solid_example.py
from dagster import Field, InputDefinition, Int, List, configured, pipeline, solid | from dagster import ( | ||||
Field, | |||||
InputDefinition, | |||||
Int, | |||||
List, | |||||
configured, | |||||
pipeline, | |||||
solid, | |||||
) | |||||
# start_configured_named | # start_configured_named | ||||
@solid( | @solid( | ||||
config_schema={ | config_schema={ | ||||
"is_sample": Field(bool, is_required=False, default_value=False), | "is_sample": Field(bool, is_required=False, default_value=False), | ||||
}, | }, | ||||
input_defs=[InputDefinition("xs", List[Int])], | input_defs=[InputDefinition("xs", List[Int])], | ||||
) | ) | ||||
def get_dataset(context, xs): | def get_dataset(context, xs): | ||||
if context.solid_config["is_sample"]: | if context.solid_config["is_sample"]: | ||||
return xs[:5] | return xs[:5] | ||||
else: | else: | ||||
return xs | return xs | ||||
# If we want to use the same solid configured in multiple ways in the same pipeline, | # If we want to use the same solid configured in multiple ways in the same pipeline, | ||||
# we have to specify unique names when configuring them: | # we have to specify unique names when configuring them: | ||||
sample_dataset = configured(get_dataset, name="sample_dataset")({"is_sample": True}) | sample_dataset = configured(get_dataset, name="sample_dataset")( | ||||
full_dataset = configured(get_dataset, name="full_dataset")({"is_sample": False}) | {"is_sample": True} | ||||
) | |||||
full_dataset = configured(get_dataset, name="full_dataset")( | |||||
{"is_sample": False} | |||||
) | |||||
@pipeline | @pipeline | ||||
def dataset_pipeline(): | def dataset_pipeline(): | ||||
sample_dataset() | sample_dataset() | ||||
full_dataset() | full_dataset() | ||||
# end_configured_named | # end_configured_named |