djs
djs

Reputation: 33

Airflow Jinja Templating - How Do I Pass query_params into my SQL file?

I'm trying to use BigQueryOperator with a templated SQL file.

Inside the SQL file query, I have (e.g.) {{ param_1 }}, {{ param_2 }}.

My query_params argument is as follows:

query_params=[
     {'name': 'param_1',
      'parameterType': {'type': 'STRING'},
      'parameterValue': {'value': 'value_1'}
     },
     {'name': 'param_2',
      'parameterType': {'type': 'STRING'},
      'parameterValue': {'value': 'value_2'}
     }
], 

but no matter what I do, the parameters aren't getting passed through. The resulting SQL just has those parameters as "".

I've tried enclosing the {{ in ', tried writing {{ query_params.param_1 }}, tried params, but I can't get it working.

What am I doing wrong?

Upvotes: 1

Views: 1033

Answers (1)

djs
djs

Reputation: 33

Solved it. Instead of query_params in the operator constructor, I need to use params which looks like:

params={'param_1': 'value_1', 'param_2': 'value_2'}

and then in the SQL file, reference these as {{ params.param_1 }}

Upvotes: 2

Related Questions