除了运算符之外,我还需要使用xcom调用SubdagOperator并将其传递给运算符的返回值。我见过很多解决方案(Airflow - How to pass xcom variable into Python function,How to retrieve a value from Airflow XCom pushed via SSHExecuteOperator等)。
他们基本上都说'variable_name':“ {{ti.xcom_pull(task_ids ='some_task_id')}}”“
但是我的Jinja模板一直以字符串形式呈现,并且不返回实际变量。有什么想法吗?
这是我当前在主dag中的代码:
PARENT_DAG_NAME = 'my_main_dag'
CHILD_DAG_NAME = 'run_featurization_dag'
run_featurization_task = SubDagOperator(
task_id=CHILD_DAG_NAME,
subdag=run_featurization_sub_dag(PARENT_DAG_NAME, CHILD_DAG_NAME, default_args, cur_date, "'{{ ti.xcom_pull(task_ids='get_num_accounts', dag_id='" + PARENT_DAG_NAME + "') }}'" ),
default_args=default_args,
dag=main_dag
)
答案 0 :(得分:1)
引号过多?试试这个
"{{ ti.xcom_pull(task_ids='get_num_accounts', dag_id='" + PARENT_DAG_NAME + "') }}"
答案 1 :(得分:0)
Jinja模板仅适用于某些参数,而不是全部。
You can use Jinja templating with every parameter that is marked as “templated” in the documentation. Template substitution occurs just before the pre_execute function of your operator is called.
https://airflow.apache.org/concepts.html#jinja-templating
因此,恐怕您不能以这种方式传递变量。