Ops in a job may have input definitions that don't correspond to the outputs of upstream ops.
Values for these inputs can be provided in a few ways. Dagster will check the following, in order, and use the first available:
Input manager - If the input to a job comes from an external source, such as a table in a database, you may want to define a resource responsible for loading it. This makes it easy to swap out implementations in different jobs and mock it in tests.
A special I/O manager, which can be referenced from Ins, can be used to load unconnected inputs. Refer to the I/O manager documentation for more information about I/O managers.
When you have an op at the beginning of a job that operates on a built-in Dagster type like string or int, you can provide a value for that input via run config.
Here's a basic job with an unconnected string input:
When you have an op at the beginning of your job that operates on a Dagster type that you've defined, you can write your own DagsterTypeLoader to define how to load that input via run config.
Providing an input manager for unconnected inputs#
When you have an op at the beginning of a job that operates on data from an external source, you might wish to separate that I/O from your op's business logic, in the same way you would with an I/O manager if the op were loading from an upstream output.
Use the following tabs to learn about how to achieve this in Dagster.
To use Table1InputManager to store outputs or override the load_input method of an I/O manager used elsewhere in the job, another option is to implement an instance of IOManager:
# in this example, TableIOManager is defined elsewhere and we just want to override load_inputclassTable1IOManager(TableIOManager):defload_input(self, context: InputContext):return read_dataframe_from_table(name="table_1")@job(resource_defs={"load_input_manager": Table1IOManager()})defio_load_table_job():
my_op()
In any of the examples in Option 1 or Option 2, setting the input_manager_key on an In controls how that input is loaded.
When launching a run, you might want to parameterize how particular inputs are loaded.
To accomplish this, you can define an input_config_schema on the I/O manager or input manager definition. The load_input function can access this config when storing or loading data, via the InputContext:
You might want to execute a subset of ops in your job and control how the inputs of those ops are loaded. Custom input managers also help in these situations, because the inputs at the beginning of the subset become unconnected inputs.
For example, you might have op1 that normally produces a table that op2 consumes. To debug op2, you might want to run it on a different table than the one normally produced by op1.
To accomplish this, you can set up the input_manager_key on op2's In to point to an input manager with the desired loading behavior. As in the previous example, setting the input_manager_key on an In controls how that input is loaded and you can write custom loading logic.
So far, this is set up so that op2 always loads table_1 even if you execute the full job. This would let you debug op2, but if you want to write this so that op2 only loads table_1 when no input is provided from an upstream op, you can rewrite the input manager as a subclass of the IO manager used for the rest of the job as follows:
classMyNewInputLoader(MyIOManager):defload_input(self, context: InputContext):if context.upstream_output isNone:# load input from table since there is no upstream outputreturn read_dataframe_from_table(name="table_1")else:returnsuper().load_input(context)
Now, when running the full job, op2's input will be loaded using the IO manager on the output of op1. When running the job subset, op2's input has no upstream output, so table_1 will be loaded.