【问题标题】:How >> operator defines task dependencies in Airflow?>> 运算符如何定义 Airflow 中的任务依赖关系?
【发布时间】:2019-02-22 15:20:43
【问题描述】:

我正在阅读 Apache Airflow 教程 https://github.com/hgrif/airflow-tutorial 并遇到了定义任务依赖项的这一部分。

with DAG('airflow_tutorial_v01',
     default_args=default_args,
     schedule_interval='0 * * * *',
     ) as dag:

print_hello = BashOperator(task_id='print_hello',
                           bash_command='echo "hello"')
sleep = BashOperator(task_id='sleep',
                     bash_command='sleep 5')
print_world = PythonOperator(task_id='print_world',
                             python_callable=print_world)


print_hello >> sleep >> print_world

让我感到困惑的是

print_hello >> sleep >> print_world

>> 在 Python 中是什么意思?我知道按位运算符,但不能与这里的代码相关。

【问题讨论】:

  • 是的,>> 默认情况下是按位移位的,但您可以在自己的类中将其定义为您想要的任何内容。 Airflow 已将其定义为排序运算符。
  • + 是数字的加法,也是字符串或列表的连接。这是一样的。 >> 是数字的位移位,但气流的顺序。
  • aah 运算符重载(如果我没记错的话)。
  • 是的,这确实是正确的。
  • 标记为operatorsbit-shift。标记这些尤其重要,因为它们无法通过搜索找到

标签: python operators airflow bit-shift


【解决方案1】:

Airflow 将工作流表示为有向无环图。工作流是必须并行或顺序执行的任意数量的任务。 “>>”是 Airflow 语法,用于将任务设置在另一个任务的下游。

深入了解incubator-airflow 项目repo,airflow 目录中的models.py 定义了Airflow 的许多高级抽象的行为。如果您愿意,您可以深入研究其他类,但回答您问题的类是 BaseOperator 类。 Airflow 中的所有运算符都继承自 BaseOperator。 BaseOperator 类的__rshift__ 方法在设置任务或另一个下游的DAG 的上下文中实现了Python 右移逻辑运算符。

参见实现here

【讨论】:

  • 该行的链接进入主分支。我建议选择一个特定的分支,以便版本更改不会影响链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-11
  • 2020-09-17
  • 2020-10-04
  • 2021-04-03
相关资源
最近更新 更多