Airflow BigQueryCreateEmptyTableOperator 的参数 'if_exists='skip' 无效

Invalid Argument 'if_exists='skip' for Airflow BigQueryCreateEmptyTableOperator

提问人:DannyRosen 提问时间:6/28/2023 更新时间:6/28/2023 访问量:106

问:

我正在尝试使用 Airflow 运算符来检查 BigQuery 表是否存在,并创建具有给定架构的表(如果它不存在),或者如果它确实存在,则转到下一个运算符。BigQueryCreateEmptyTableOperator

我的运算符构造函数如下:

check_and_create_table = BigQueryCreateEmptyTableOperator(
        task_id='check_and_create_final_table',
        project_id = GCP_PROJECT,
        dataset_id = BQ_DATASET,
        table_id = BQ_TABLE,
        schema_fields=get_final_schema(),
        if_exists='skip'
    )

根据 Airflow 文档,应将参数设置为 以实现此目的。不幸的是,我在 Airflow 中收到 DAG 导入错误,内容如下:if_exists'skip'

  File "/home/airflow/.local/lib/python3.10/site-packages/airflow/models/baseoperator.py", line 408, in apply_defaults
    result = func(self, **kwargs, default_args=default_args)
  File "/home/airflow/.local/lib/python3.10/site-packages/airflow/models/baseoperator.py", line 756, in __init__
    raise AirflowException(
airflow.exceptions.AirflowException: Invalid arguments were passed to BigQueryCreateEmptyTableOperator (task_id: check_and_create_final_table). Invalid arguments were:
**kwargs: {'if_exists': 'skip'}

如果有人有任何想法,他们将不胜感激。

google-cloud-platform google-bigquery airflow direct-acyclic-graphs invalid-argument

评论

0赞 ozs 6/28/2023
您使用的是哪个版本的 Airflow?我认为它仅来自 2.6,您应该改用 exist_ok
0赞 DannyRosen 6/28/2023
2.4.3,这将解释它。非常感谢!

答:

1赞 ozs 6/28/2023 #1

if_exists Airflow 版本 2.6 中实现exist_ok因此已弃用。

对于 2.6 之前的版本,您应该使用 exist_ok 作为替代

这是公关