2.8 Input Operator
The input operator is used to read a value from an input source. It allways as the first Operator in a DAG, and it allows you easily to write your own input source.
The input operator is a special operator, it does not have any input, and it has one output.
There are one way to use the input operator:
Build A InputOperator
With A Input Source
Just pass the input source to the InputOperator
constructor.
from dbgpt.core.awel import DAG, InputOperator, SimpleInputSource
with DAG("awel_input_operator") as dag:
input_source = SimpleInputSource(data="Hello, World!")
input_task = InputOperator(input_source=input_source)
Examples
Print The Input Data
This example shows how to use the InputOperator
to print the input data, it uses
SimpleInputSource
which is build with a string data as input source.
Create a new file named input_operator_print_data.py
in the awel_tutorial
directory
and add the following code:
import asyncio
from dbgpt.core.awel import DAG, MapOperator, InputOperator, SimpleInputSource
with DAG("awel_input_operator") as dag:
input_source = SimpleInputSource(data="Hello, World!")
input_task = InputOperator(input_source=input_source)
print_task = MapOperator(map_function=lambda x: print(x))
input_task >> print_task
asyncio.run(print_task.call())
And run the following command to execute the code:
poetry run python awel_tutorial/input_operator_print_data.py
And you will see the following output:
Hello, World!