Skip to content

Commit 85c7b9f

Browse files
committed
suggested updates: reduce duplicate code, change query_params
1 parent aa6b9eb commit 85c7b9f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

google/cloud/bigquery/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,9 @@ def update_table(
14431443
path = table.path
14441444
span_attributes = {"path": path, "fields": fields}
14451445

1446+
query_params = {}
14461447
if autodetect_schema:
1447-
query_params = {"autodetect_schema": True}
1448-
else:
1449-
query_params = None
1448+
query_params["autodetect_schema"] = True
14501449

14511450
api_response = self._call_api(
14521451
retry,

tests/system/test_client.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,8 @@ def test_update_table_autodetect_schema(self):
985985
TABLE_NAME = "test_table"
986986
set_schema = [bigquery.SchemaField("username", "STRING", mode="NULLABLE")]
987987
table_arg = Table(dataset.table(TABLE_NAME))
988+
989+
# Create an external_config and include it in the table arguments
988990
external_config = bigquery.ExternalConfig(bigquery.ExternalSourceFormat.AVRO)
989991
external_config.source_uris = SOURCE_URIS_AVRO
990992
external_config.reference_file_schema_uri = REFERENCE_FILE_SCHEMA_URI_AVRO
@@ -1001,13 +1003,9 @@ def test_update_table_autodetect_schema(self):
10011003

10021004
# Update table with schema autodetection
10031005
updated_table_arg = Table(dataset.table(TABLE_NAME))
1004-
updated_external_config = bigquery.ExternalConfig(
1005-
bigquery.ExternalSourceFormat.AVRO
1006-
)
1007-
updated_external_config.source_uris = SOURCE_URIS_AVRO
1008-
updated_external_config.reference_file_schema_uri = (
1009-
REFERENCE_FILE_SCHEMA_URI_AVRO
1010-
)
1006+
1007+
# Update the external_config and include it in the updated table arguments
1008+
updated_external_config = copy.deepcopy(external_config)
10111009
updated_external_config.autodetect = True
10121010
updated_external_config.schema = None
10131011
updated_table_arg.external_data_configuration = updated_external_config
@@ -1016,7 +1014,7 @@ def test_update_table_autodetect_schema(self):
10161014
updated_table_arg, ["external_data_configuration"], autodetect_schema=True
10171015
)
10181016

1019-
# The updated table shlould have a schema inferred from the reference
1017+
# The updated table should have a schema inferred from the reference
10201018
# file, which has all four fields.
10211019
expected_schema = [
10221020
bigquery.SchemaField("username", "STRING", mode="NULLABLE"),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy