Skip to content

feat: add ability to set autodetect_schema query param in update_table #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! Add ability to set autodetect_schema query_param
  • Loading branch information
TheNeuralBit committed May 12, 2025
commit b329cd0aa330999e481f9436580508a0c2ff015f
15 changes: 7 additions & 8 deletions tests/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ def test_update_table_autodetect_schema(self):
TABLE_NAME = "test_table"
set_schema = [bigquery.SchemaField("username", "STRING", mode="NULLABLE")]
table_arg = Table(dataset.table(TABLE_NAME))

# Create an external_config and include it in the table arguments
external_config = bigquery.ExternalConfig(bigquery.ExternalSourceFormat.AVRO)
external_config.source_uris = SOURCE_URIS_AVRO
external_config.reference_file_schema_uri = REFERENCE_FILE_SCHEMA_URI_AVRO
Expand All @@ -1001,22 +1003,19 @@ def test_update_table_autodetect_schema(self):

# Update table with schema autodetection
updated_table_arg = Table(dataset.table(TABLE_NAME))
updated_external_config = bigquery.ExternalConfig(
bigquery.ExternalSourceFormat.AVRO
)
updated_external_config.source_uris = SOURCE_URIS_AVRO
updated_external_config.reference_file_schema_uri = (
REFERENCE_FILE_SCHEMA_URI_AVRO
)

# Update the external_config and include it in the table arguments
updated_external_config = copy.deepcopy(external_config)
updated_external_config.autodetect = True
updated_external_config.schema = None
updated_table_arg.external_data_configuration = updated_external_config

# PATCH call with autodetect_schema=True to trigger schema inference
updated_table = Config.CLIENT.update_table(
updated_table_arg, ["external_data_configuration"], autodetect_schema=True
)

# The updated table shlould have a schema inferred from the reference
# The updated table should have a schema inferred from the reference
# file, which has all four fields.
expected_schema = [
bigquery.SchemaField("username", "STRING", mode="NULLABLE"),
Expand Down