Content-Length: 411699 | pFad | https://github.com/apache/airflow/commit/79c99b1b6ae2ff5b0c8ab892f7f3fb1b44724121

A9 Added location parameter to BigQueryCheckOperator (#8273) · apache/airflow@79c99b1 · GitHub
Skip to content

Commit 79c99b1

Browse files
authored
Added location parameter to BigQueryCheckOperator (#8273)
1 parent dd9f04e commit 79c99b1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

airflow/providers/google/cloud/hooks/bigquery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,7 @@ def next(self) -> Union[List, None]:
24452445
query_results = (self.service.jobs().getQueryResults(
24462446
projectId=self.project_id,
24472447
jobId=self.job_id,
2448+
location=self.location,
24482449
pageToken=self.page_token).execute(num_retries=self.num_retries))
24492450

24502451
if 'rows' in query_results and query_results['rows']:

airflow/providers/google/cloud/operators/bigquery.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class BigQueryCheckOperator(CheckOperator):
7777
:param use_legacy_sql: Whether to use legacy SQL (true)
7878
or standard SQL (false).
7979
:type use_legacy_sql: bool
80+
:param location: The geographic location of the job. Required except for
81+
US and EU. See details at
82+
https://cloud.google.com/bigquery/docs/locations#specifying_your_location
83+
:type location: str
8084
"""
8185

8286
template_fields = ('sql', 'gcp_conn_id',)
@@ -88,6 +92,7 @@ def __init__(self,
8892
gcp_conn_id: str = 'google_cloud_default',
8993
bigquery_conn_id: Optional[str] = None,
9094
use_legacy_sql: bool = True,
95+
location=None,
9196
*args, **kwargs) -> None:
9297
super().__init__(sql=sql, *args, **kwargs)
9398
if bigquery_conn_id:
@@ -99,10 +104,12 @@ def __init__(self,
99104
self.gcp_conn_id = gcp_conn_id
100105
self.sql = sql
101106
self.use_legacy_sql = use_legacy_sql
107+
self.location = location
102108

103109
def get_db_hook(self):
104110
return BigQueryHook(bigquery_conn_id=self.gcp_conn_id,
105-
use_legacy_sql=self.use_legacy_sql)
111+
use_legacy_sql=self.use_legacy_sql,
112+
location=self.location)
106113

107114

108115
class BigQueryValueCheckOperator(ValueCheckOperator):

tests/providers/google/cloud/hooks/test_bigquery.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
TABLE_ID = "bq_table"
3535
VIEW_ID = 'bq_view'
3636
JOB_ID = 1234
37+
LOCATION = 'europe-north1'
3738

3839

3940
class TestBigQueryHookMethods(unittest.TestCase):
@@ -1612,14 +1613,16 @@ def test_next(self, mock_get_service, mock_get_creds_and_proj_id):
16121613
bq_hook = hook.BigQueryHook()
16131614
bq_cursor = bq_hook.get_cursor()
16141615
bq_cursor.job_id = JOB_ID
1616+
bq_cursor.location = LOCATION
16151617

16161618
result = bq_cursor.next()
16171619
self.assertEqual(['one', 1], result)
16181620

16191621
result = bq_cursor.next()
16201622
self.assertEqual(['two', 2], result)
16211623

1622-
mock_get_query_results.assert_called_once_with(jobId=JOB_ID, pageToken=None, projectId='bq-project')
1624+
mock_get_query_results.assert_called_once_with(jobId=JOB_ID, location=LOCATION, pageToken=None,
1625+
projectId='bq-project')
16231626
mock_execute.assert_called_once_with(num_retries=bq_cursor.num_retries)
16241627

16251628
@mock.patch(
@@ -1640,7 +1643,8 @@ def test_next_no_rows(self, mock_flush_results, mock_get_service, mock_get_creds
16401643
result = bq_cursor.next()
16411644

16421645
self.assertIsNone(result)
1643-
mock_get_query_results.assert_called_once_with(jobId=JOB_ID, pageToken=None, projectId='bq-project')
1646+
mock_get_query_results.assert_called_once_with(jobId=JOB_ID, location=None, pageToken=None,
1647+
projectId='bq-project')
16441648
mock_execute.assert_called_once_with(num_retries=bq_cursor.num_retries)
16451649
assert mock_flush_results.call_count == 1
16461650

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/apache/airflow/commit/79c99b1b6ae2ff5b0c8ab892f7f3fb1b44724121

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy