gpt4 book ai didi

global-variables - Airflow 中的全局变量

转载 作者:行者123 更新时间:2023-12-05 00:58:01 25 4
gpt4 key购买 nike

我正在尝试使用 Airflow 来实现基本的 ETL 工作,但停留在一点:

我有 3 个功能。我想为它们中的每一个定义全局变量,例如:

function a():
return a_result

function b():
use a
return b_result
function c():
use a and b

然后在python_callable中使用这些函数。

像往常一样定义 global a_result 不起作用。有什么解决办法吗?

最佳答案

正如我在评论中所写,

When you return something in your python_callable, you can access the returned value if you pass the task context to the next operator. https://airflow.apache.org/concepts.html?highlight=xcom

以下是说明这个想法的半伪代码

# inside a PythonOperator called 'pushing_task' 
def push_function():
return value

# inside another PythonOperator where provide_context=True
def pull_function(**context):
value = context['task_instance'].xcom_pull(task_ids='pushing_task')

pushing_task = PythonOperator('pushing_task',
push_function, ...)

pulling_task = PythonOperator('pulling_task',
pull_function,
provide_context=True ...)

关于global-variables - Airflow 中的全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58792721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com