Fetch results from BigQueryOperator in airflow
I followed the suggestion in above link, the solution works and it is good and it works if my sql is a single line. but if SQL code is large and place it in a file and reference the file in the function then fails.
def MyChequer(**kwargs):
big_query_count = bigquery_operator.BigQueryOperator(
task_id='my_bq_query',
sql='/dags/sqls/invalidTable.sql'
)
Then I get error : BigQuery job failed. Final error was: {'reason': 'invalidQuery', 'location': 'query', 'message': 'Syntax error: Unexpected identifier "dags" at [1:1]'}
Normally I use in following way and the below works
BigQueryOperator(
task_id='invalidXXX',
use_legacy_sql=False,
sql='/dags/sqls/invalid_v1.sql',
destination_dataset_table=targetTable,
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_TRUNCATE',
dag=dag
)
dag = DAG('invalidXXX',
default_args=default_args,
description='',
schedule_interval="0 5 * * *",
catchup=False,
template_searchpath=['/home/airflow/stgAirflow/']
)