使用气流蜂巢运算符并输出到文本文件

use*_*180 5 python airflow airflow-scheduler

嗨,我想使用气流配置单元运算符执行配置单元查询并将结果输出到文件。我不想在这里使用 INSERT OVERWRITE。

hive_ex = HiveOperator(
    task_id='hive-ex',
    hql='/sql/hive-ex.sql',
    hiveconfs={
        'DAY': '{{ ds }}',
        'YESTERDAY': '{{ yesterday_ds }}',
        'OUTPUT': '{{ file_path }}'+'csv',
    },
    dag=dag
)
Run Code Online (Sandbox Code Playgroud)

做这个的最好方式是什么?

我知道如何使用 bash 运算符执行此操作,但想知道我们是否可以使用 hive 运算符

hive_ex = BashOperator(
    task_id='hive-ex',
    bash_command='hive -f hive.sql -DAY={{ ds }} >> {{ file_path }} 
    /file_{{ds}}.json',
    dag=dag
)
Run Code Online (Sandbox Code Playgroud)

fen*_* ce 2

你需要气流挂钩。参见Hooks和HiveHook,有一个to_csv方法或者你可以使用get_records方法然后自己做。