Solid Events
A solid can yield a stream of events within its compute_fn
to
communicate with the Dagster framework. These events must be one of the
following types:
Output
AssetMaterialization
ExpectationResult
TypeCheck
Failure
(meant to be raised)
To return an output from a solid, simply yield
an Output
event:
@solid
def my_yield_solid(context):
yield Output(1)
Many solids yield only one output, like the example above. Returning a
single value from a solid's compute_fn
is equivalent to yielding a
single Output
event
with the default output name "result". For example:
@solid
def return_solid(context):
return 1
# Is equivalent to
@solid
def yield_solid(context):
yield Output(1, "result")
Note that you cannot yield
a single value without wrapping it in Output
.
This is because a solid can yield arbitrarily many values, and there's no way
for the system to tell which one the author of the solid meant to use as
its output. For example:
# This is invalid
@solid
def incorrect_solid(context):
yield 1
If you want to have multiple outputs for a solid, you cannot return
anything from the solid. Instead, you need to yield
multiple Output
events,
each of which is named and defined on output_defs
to prevent ambiguity:
@solid(output_defs=[OutputDefinition(name="output_1"), OutputDefinition(name="output_2")])
def multiple_output_solid(context):
yield Output(1, output_name="output_1")
yield Output(2, output_name="output_2")