Skip to content

Commit

Permalink
Add support for query parameters to BigQueryCheckOperator (#40556)
Browse files Browse the repository at this point in the history
Remove unnecessary space
  • Loading branch information
aldenpagedv committed Jul 2, 2024
1 parent 015ac89 commit 14d6469
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions airflow/providers/google/cloud/operators/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,20 @@ class BigQueryCheckOperator(
:param deferrable: Run operator in the deferrable mode.
:param poll_interval: (Deferrable mode only) polling period in seconds to
check for the status of job.
:param query_params: a list of dictionary containing query parameter types and
values, passed to BigQuery. The structure of dictionary should look like
'queryParameters' in Google BigQuery Jobs API:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs.
For example, [{ 'name': 'corpus', 'parameterType': { 'type': 'STRING' },
'parameterValue': { 'value': 'romeoandjuliet' } }]. (templated)
"""

template_fields: Sequence[str] = (
"sql",
"gcp_conn_id",
"impersonation_chain",
"labels",
"query_params",
)
template_ext: Sequence[str] = (".sql",)
ui_color = BigQueryUIColors.CHECK.value
Expand All @@ -246,6 +253,7 @@ def __init__(
encryption_configuration: dict | None = None,
deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
poll_interval: float = 4.0,
query_params: list | None = None,
**kwargs,
) -> None:
super().__init__(sql=sql, **kwargs)
Expand All @@ -257,6 +265,7 @@ def __init__(
self.encryption_configuration = encryption_configuration
self.deferrable = deferrable
self.poll_interval = poll_interval
self.query_params = query_params

def _submit_job(
self,
Expand All @@ -265,6 +274,8 @@ def _submit_job(
) -> BigQueryJob:
"""Submit a new job and get the job id for polling the status using Trigger."""
configuration = {"query": {"query": self.sql, "useLegacySql": self.use_legacy_sql}}
if self.query_params:
configuration["query"]["queryParameters"] = query_params

self.include_encryption_configuration(configuration, "query")

Expand Down

0 comments on commit 14d6469

Please sign in to comment.