自Apache Airflow 1.9发行以来,我一直在使用自己的自定义SqlSensor,因为我无法使用在Google BigQuery上运行的Standard SQL语句中包含的SqlSensor,因为默认值为use legacy SQL。
我检查了最近的1.10.3版本,看来情况仍然如此。除了使用我自己的SQL传感器作为插件之外,还有其他方法可以实现此目的吗?
答案 0 :(得分:0)
从文档中的enabling standard SQL主题开始,如果您不能直接设置该选项,另一种方法是使用#standardSQL
shebang,例如:
#standardSQL
SELECT x
FROM UNNEST([1, 2, 3]) AS x;
应该可以使用该前缀提交查询以覆盖设置。
答案 1 :(得分:0)
更新您的自定义传感器,以将use_legacy_sql=False
传递到BigQueryHook。
hook = BigQueryHook(
bigquery_conn_id=self.bigquery_conn_id,
delegate_to=self.delegate_to,
use_legacy_sql=False
)
答案 2 :(得分:0)
我找到的最快的解决方案是
_get_hook
方法use_legacy_sql=False
from airflow.sensors.sql_sensor import SqlSensor
class BigQuerySqlSensor(SqlSensor):
def _get_hook(self):
hook = super()._get_hook()
hook.use_legacy_sql = False
return hook
sense_stuff = BigQuerySqlSensor(
dag=dag,
task_id='sense_stuff',
conn_id='the_connection_id',
sql="SELECT COUNT(*) FROM some_table",
mode='reschedule',
poke_interval=600,
timeout=(3600)
)