Skip to content

Commit fc6dfa3

Browse files
Support project_id argument in BigQueryGetDataOperator (#25782)
1 parent 98a7701 commit fc6dfa3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,16 @@ class BigQueryGetDataOperator(BaseOperator):
361361
task_id='get_data_from_bq',
362362
dataset_id='test_dataset',
363363
table_id='Transaction_partitions',
364+
project_id='internal-gcp-project',
364365
max_results=100,
365366
selected_fields='DATE',
366367
gcp_conn_id='airflow-conn-id'
367368
)
368369
369370
:param dataset_id: The dataset ID of the requested table. (templated)
370371
:param table_id: The table ID of the requested table. (templated)
372+
:param project_id: (Optional) The name of the project where the data
373+
will be returned from. (templated)
371374
:param max_results: The maximum number of records (rows) to be fetched
372375
from the table. (templated)
373376
:param selected_fields: List of fields to return (comma-separated). If
@@ -390,6 +393,7 @@ class BigQueryGetDataOperator(BaseOperator):
390393
template_fields: Sequence[str] = (
391394
'dataset_id',
392395
'table_id',
396+
'project_id',
393397
'max_results',
394398
'selected_fields',
395399
'impersonation_chain',
@@ -401,6 +405,7 @@ def __init__(
401405
*,
402406
dataset_id: str,
403407
table_id: str,
408+
project_id: Optional[str] = None,
404409
max_results: int = 100,
405410
selected_fields: Optional[str] = None,
406411
gcp_conn_id: str = 'google_cloud_default',
@@ -419,6 +424,7 @@ def __init__(
419424
self.delegate_to = delegate_to
420425
self.location = location
421426
self.impersonation_chain = impersonation_chain
427+
self.project_id = project_id
422428

423429
def execute(self, context: 'Context') -> list:
424430
self.log.info(
@@ -445,6 +451,7 @@ def execute(self, context: 'Context') -> list:
445451
max_results=self.max_results,
446452
selected_fields=self.selected_fields,
447453
location=self.location,
454+
project_id=self.project_id,
448455
)
449456

450457
self.log.info('Total extracted rows: %s', len(rows))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ def test_execute(self, mock_hook):
717717
task_id=TASK_ID,
718718
dataset_id=TEST_DATASET,
719719
table_id=TEST_TABLE_ID,
720+
project_id=TEST_GCP_PROJECT_ID,
720721
max_results=max_results,
721722
selected_fields=selected_fields,
722723
location=TEST_DATASET_LOCATION,
@@ -725,6 +726,7 @@ def test_execute(self, mock_hook):
725726
mock_hook.return_value.list_rows.assert_called_once_with(
726727
dataset_id=TEST_DATASET,
727728
table_id=TEST_TABLE_ID,
729+
project_id=TEST_GCP_PROJECT_ID,
728730
max_results=max_results,
729731
selected_fields=selected_fields,
730732
location=TEST_DATASET_LOCATION,

0 commit comments

Comments
 (0)