Skip to content

Commit

Permalink
Deprecate remaining occurrences of bigquery_conn_id in favor of `gc…
Browse files Browse the repository at this point in the history
…p_conn_id` (#24376)

* Replace the remaining occurrences of bigquery_conn_id with gcp_conn_id
* Deprecate remaining bigquery_conn_id usages

Co-authored-by: Kian <[email protected]>
  • Loading branch information
kianelbo and Kian committed Jun 12, 2022
1 parent dd78e29 commit 8e0bdda
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions airflow/providers/google/cloud/operators/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ class BigQueryCreateEmptyTableOperator(BaseOperator):
.. seealso::
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#timePartitioning
:param bigquery_conn_id: [Optional] The connection ID used to connect to Google Cloud and
:param gcp_conn_id: [Optional] The connection ID used to connect to Google Cloud and
interact with the Bigquery service.
:param google_cloud_storage_conn_id: [Optional] The connection ID used to connect to Google Cloud.
and interact with the Google Cloud Storage service.
Expand All @@ -726,7 +726,7 @@ class BigQueryCreateEmptyTableOperator(BaseOperator):
table_id='Employees',
project_id='internal-gcp-project',
gcs_schema_object='gs://schema-bucket/employee_schema.json',
bigquery_conn_id='airflow-conn-id',
gcp_conn_id='airflow-conn-id',
google_cloud_storage_conn_id='airflow-conn-id'
)
Expand Down Expand Up @@ -754,7 +754,7 @@ class BigQueryCreateEmptyTableOperator(BaseOperator):
project_id='internal-gcp-project',
schema_fields=[{"name": "emp_name", "type": "STRING", "mode": "REQUIRED"},
{"name": "salary", "type": "INTEGER", "mode": "NULLABLE"}],
bigquery_conn_id='airflow-conn-id-account',
gcp_conn_id='airflow-conn-id-account',
google_cloud_storage_conn_id='airflow-conn-id'
)
:param view: [Optional] A dictionary containing definition for the view.
Expand Down Expand Up @@ -811,7 +811,8 @@ def __init__(
schema_fields: Optional[List] = None,
gcs_schema_object: Optional[str] = None,
time_partitioning: Optional[Dict] = None,
bigquery_conn_id: str = 'google_cloud_default',
gcp_conn_id: str = 'google_cloud_default',
bigquery_conn_id: Optional[str] = None,
google_cloud_storage_conn_id: str = 'google_cloud_default',
delegate_to: Optional[str] = None,
labels: Optional[Dict] = None,
Expand All @@ -824,14 +825,22 @@ def __init__(
exists_ok: bool = False,
**kwargs,
) -> None:
if bigquery_conn_id:
warnings.warn(
"The bigquery_conn_id parameter has been deprecated. Use the gcp_conn_id parameter instead.",
DeprecationWarning,
stacklevel=2,
)
gcp_conn_id = bigquery_conn_id

super().__init__(**kwargs)

self.project_id = project_id
self.dataset_id = dataset_id
self.table_id = table_id
self.schema_fields = schema_fields
self.gcs_schema_object = gcs_schema_object
self.bigquery_conn_id = bigquery_conn_id
self.gcp_conn_id = gcp_conn_id
self.google_cloud_storage_conn_id = google_cloud_storage_conn_id
self.delegate_to = delegate_to
self.time_partitioning = {} if time_partitioning is None else time_partitioning
Expand All @@ -847,7 +856,7 @@ def __init__(

def execute(self, context: 'Context') -> None:
bq_hook = BigQueryHook(
gcp_conn_id=self.bigquery_conn_id,
gcp_conn_id=self.gcp_conn_id,
delegate_to=self.delegate_to,
location=self.location,
impersonation_chain=self.impersonation_chain,
Expand Down Expand Up @@ -949,7 +958,7 @@ class BigQueryCreateExternalTableOperator(BaseOperator):
columns are treated as bad records, and if there are too many bad records, an
invalid error is returned in the job result. Only applicable to CSV, ignored
for other formats.
:param bigquery_conn_id: (Optional) The connection ID used to connect to Google Cloud and
:param gcp_conn_id: (Optional) The connection ID used to connect to Google Cloud and
interact with the Bigquery service.
:param google_cloud_storage_conn_id: (Optional) The connection ID used to connect to Google Cloud
and interact with the Google Cloud Storage service.
Expand Down Expand Up @@ -1006,7 +1015,8 @@ def __init__(
quote_character: Optional[str] = None,
allow_quoted_newlines: bool = False,
allow_jagged_rows: bool = False,
bigquery_conn_id: str = 'google_cloud_default',
gcp_conn_id: str = 'google_cloud_default',
bigquery_conn_id: Optional[str] = None,
google_cloud_storage_conn_id: str = 'google_cloud_default',
delegate_to: Optional[str] = None,
src_fmt_configs: Optional[dict] = None,
Expand All @@ -1016,6 +1026,14 @@ def __init__(
impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
**kwargs,
) -> None:
if bigquery_conn_id:
warnings.warn(
"The bigquery_conn_id parameter has been deprecated. Use the gcp_conn_id parameter instead.",
DeprecationWarning,
stacklevel=2,
)
gcp_conn_id = bigquery_conn_id

super().__init__(**kwargs)

# BQ config
Expand Down Expand Up @@ -1085,7 +1103,7 @@ def __init__(
self.quote_character = quote_character
self.allow_quoted_newlines = allow_quoted_newlines
self.allow_jagged_rows = allow_jagged_rows
self.bigquery_conn_id = bigquery_conn_id
self.gcp_conn_id = gcp_conn_id
self.google_cloud_storage_conn_id = google_cloud_storage_conn_id
self.delegate_to = delegate_to
self.autodetect = autodetect
Expand All @@ -1098,7 +1116,7 @@ def __init__(

def execute(self, context: 'Context') -> None:
bq_hook = BigQueryHook(
gcp_conn_id=self.bigquery_conn_id,
gcp_conn_id=self.gcp_conn_id,
delegate_to=self.delegate_to,
location=self.location,
impersonation_chain=self.impersonation_chain,
Expand Down

0 comments on commit 8e0bdda

Please sign in to comment.