Skip to content

Commit 8b54919

Browse files
authored
Refactor BigQuery hook methods to use python library (#8631)
* Refactor create_external_table * Refactor patch_table and add update_table * Refactor run_grant_dataset_view_access * Refactor run_upsert_table * Refactor insert_all * Refactor delete_table * Refactor list_rows * Fix types * Fix test * Refactor poll_job_complete * Refactor cancel_query * Refactor run_with_configuration * Refactor run_* methods * Fix self.project_id issue * Fixup run_table_upsert
1 parent 7236862 commit 8b54919

File tree

7 files changed

+886
-1098
lines changed

7 files changed

+886
-1098
lines changed

UPDATING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ The previous option used a colon(`:`) to split the module from function. Now the
128128
The change aims to unify the format of all options that refer to objects in the `airflow.cfg` file.
129129

130130
### Changes in BigQueryHook
131+
In general all hook methods are decorated with `@GoogleBaseHook.fallback_to_default_project_id` thus
132+
parameters to hook can only be passed via keyword arguments.
133+
131134
- `create_empty_table` method accepts now `table_resource` parameter. If provided all
132135
other parameters are ignored.
133136
- `create_empty_dataset` will now use values from `dataset_reference` instead of raising error
@@ -137,6 +140,8 @@ changed.
137140
- `update_dataset` requires now new `fields` argument (breaking change)
138141
- `delete_dataset` has new signature (dataset_id, project_id, ...)
139142
previous one was (project_id, dataset_id, ...) (breaking change)
143+
- `get_tabledata` returns list of rows instead of API response in dict format. This method is deprecated in
144+
favor of `list_rows`. (breaking change)
140145

141146
### Added mypy plugin to preserve types of decorated functions
142147

airflow/providers/google/cloud/example_dags/example_bigquery_operations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "example-project")
3939
BQ_LOCATION = "europe-north1"
4040

41-
DATASET_NAME = os.environ.get("GCP_BIGQUERY_DATASET_NAME", "test_dataset")
41+
DATASET_NAME = os.environ.get("GCP_BIGQUERY_DATASET_NAME", "test_dataset_operations")
4242
LOCATION_DATASET_NAME = "{}_location".format(DATASET_NAME)
4343
DATA_SAMPLE_GCS_URL = os.environ.get(
4444
"GCP_BIGQUERY_DATA_GCS_URL",
@@ -71,7 +71,7 @@
7171
# [START howto_operator_bigquery_delete_table]
7272
delete_table = BigQueryDeleteTableOperator(
7373
task_id="delete_table",
74-
deletion_dataset_table="{}.test_table".format(DATASET_NAME),
74+
deletion_dataset_table=f"{PROJECT_ID}.{DATASET_NAME}.test_table",
7575
)
7676
# [END howto_operator_bigquery_delete_table]
7777

@@ -89,7 +89,7 @@
8989

9090
# [START howto_operator_bigquery_delete_view]
9191
delete_view = BigQueryDeleteTableOperator(
92-
task_id="delete_view", deletion_dataset_table=f"{DATASET_NAME}.test_view"
92+
task_id="delete_view", deletion_dataset_table=f"{PROJECT_ID}.{DATASET_NAME}.test_view"
9393
)
9494
# [END howto_operator_bigquery_delete_view]
9595

airflow/providers/google/cloud/example_dags/example_bigquery_queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
task_id="get_data",
116116
dataset_id=DATASET_NAME,
117117
table_id=TABLE_1,
118-
max_results="10",
118+
max_results=10,
119119
selected_fields="value,name",
120120
)
121121
# [END howto_operator_bigquery_get_data]

0 commit comments

Comments
 (0)