Google bigquery 未使用的BigQueryOperator将查询传递给BigQuery

Google bigquery 未使用的BigQueryOperator将查询传递给BigQuery,google-bigquery,airflow,Google Bigquery,Airflow,在使用BigQueryOperator将查询发布到BigQuery时,我面临着挑战。 气流版本:1.10.6 一段代码 args = { 'owner': 'Airflow', 'start_date': datetime(2019, 12, 17), 'retries': 1, } dag = DAG( dag_id='my_dag', default_args=args, schedule_interval="@daily", ) run_

在使用BigQueryOperator将查询发布到BigQuery时,我面临着挑战。 气流版本:1.10.6

一段代码

args = {
    'owner': 'Airflow',
    'start_date': datetime(2019, 12, 17),
    'retries': 1,
}

dag = DAG(
    dag_id='my_dag',
    default_args=args,
    schedule_interval="@daily",
)

run_bq_cmd = BigQueryOperator (
    task_id='execute_bq_cmd',
    sql='SELECT 1 FROM `project.dataset.table` WHERE user=@user',
    destination_dataset_table=destination_tbl,
    use_legacy_sql=False,
    write_disposition='WRITE_APPEND',
    create_disposition='CREATE_IF_NEEDED',
    allow_large_results=True,
    query_params=[
        {
            "name": "user",
            "parameterType": { "type": "STRING" },
            "parameterValue": { "value": "Amol"}
        }
    ],
    dag=dag,
)
运行此dag后,我得到以下错误

[2019-12-19 11:54:33,528] {taskinstance.py:1058} ERROR - BigQuery job failed. Final error was: {u'reason': u'invalidQuery', u'message': u'Syntax error: Unexpected identifier "S" at [1:1]', u'location': u'query'}. The job was: {u'status': {u'state': u'DONE', u'errors': [{u'reason': u'invalidQuery', u'message': u'Syntax error: Unexpected identifier "S" at [1:1]', u'location': u'query'}], u'errorResult': {u'reason': u'invalidQuery', u'message': u'Syntax error: Unexpected identifier "S" at [1:1]', u'location': u'query'}}, u'kind': u'bigquery#job', u'statistics': {u'endTime': u'1576756473354', u'creationTime': u'1576756473345', u'startTime': u'1576756473354'}, u'jobReference': {u'projectId': u'converged-dev-datahub', u'location': u'US', u'jobId': u'job_1qEYq2LaJVfSNSpGZ8e25bKOvpu3'}, u'etag': u'Q9k1LNPcvJ91NjuTD9Yo0w==', u'selfLink': u'https://bigquery.googleapis.com/bigquery/v2/projects/converged-dev-datahub/jobs/job_1qEYq2LaJVfSNSpGZ8e25bKOvpu3?location=US', u'configuration': {u'query': {u'useLegacySql': False, u'destinationTable': {u'projectId': u'converged-dev-datahub', u'tableId': u'fishhook_01_report', u'datasetId': u'dataset_for_amol'}, u'priority': u'INTERACTIVE', u'writeDisposition': u'WRITE_APPEND', u'allowLargeResults': True, u'queryParameters': [{u'parameterType': {u'type': u'STRING'}, u'parameterValue': {u'value': u'fishhook'}, u'name': u'partner'}], u'createDisposition': u'CREATE_IF_NEEDED', u'query': u'S'}, u'jobType': u'QUERY'}, u'id': u'converged-dev-datahub:US.job_1qEYq2LaJVfSNSpGZ8e25bKOvpu3', u'user_email': u'123350035192-compute@developer.gserviceaccount.com'}
Traceback (most recent call last):
  File "/root/miniconda2/lib/python2.7/site-packages/airflow/models/taskinstance.py", line 930, in _run_raw_task
    result = task_copy.execute(context=context)
  File "/root/miniconda2/lib/python2.7/site-packages/airflow/contrib/operators/bigquery_operator.py", line 268, in execute
    for s in self.sql]
  File "/root/miniconda2/lib/python2.7/site-packages/airflow/contrib/hooks/bigquery_hook.py", line 913, in run_query
    return self.run_with_configuration(configuration)
  File "/root/miniconda2/lib/python2.7/site-packages/airflow/contrib/hooks/bigquery_hook.py", line 1344, in run_with_configuration
    format(job['status']['errorResult'], job))
虽然很奇怪,但我看到查询的唯一开始字符是SELECT的“S”,它被传递给BigQuery

在气流日志中,我正确地看到了我的查询

[2019-12-19 11:54:33,083] {bigquery_operator.py:218} INFO - Executing: SELECT 1 FROM `project.dataset.table` WHERE user=@user

指定BigQueryOperator时是否遗漏了一些内容?

如果使用unicode字符串,有什么区别吗
sql=u'SELECT 1 FROM…
也尝试了使用unicode,但没有成功:(解决了问题..我将其作为列表而不是字符串。
sql=['SELECT 1 FROM…]
有趣的是,允许使用字符串或字符串列表,您使用的气流版本是什么?是的。甚至我都很惊讶…使用字符串排在第一位的原因是,doc确实说它接受字符串,但不幸的是,它至少对我不起作用。我使用的气流版本是1.10.6。如果使用unicode字符串,会有任何区别吗?
sql=u'SELECT 1 FROM…
也尝试使用unicode,但没有成功:(解决了问题..我将其作为列表而不是字符串。
sql=['SELECT 1 FROM…]
有趣的是,允许使用字符串或字符串列表,您使用的气流版本是什么?是的。甚至我都很惊讶…使用字符串排在第一位的原因是,doc确实说它接受字符串,但不幸的是,它至少对我不起作用。我使用的气流版本是1.10.6