Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 324
feat: Adds source_column_match and associated tests#2227
Merged
gcf-merge-on-green
merged 14 commits into
main
from
feat-374142081-add-source-column-matchJul 15, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fc3dbf7
Adds source_column_match and associated tests
chalmerlowe 88c3775
Update google/cloud/bigquery/job/load.py
chalmerlowe 9403046
Update google/cloud/bigquery/external_config.py
chalmerlowe b6261dc
Update google/cloud/bigquery/job/load.py
chalmerlowe 964b1d0
Update google/cloud/bigquery/external_config.py
chalmerlowe c25727d
updates docstring to account for sphinx unexpected indent warning
chalmerlowe 3b39fc3
Merge branch 'main' into feat-374142081-add-source-column-match
chalmerlowe 5686794
Merge branch 'main' into feat-374142081-add-source-column-match
chalmerlowe c31b1ad
Merge branch 'main' into feat-374142081-add-source-column-match
chalmerlowe b7eabe1
Updates docstrings and tests
chalmerlowe 3b10ee1
Merge branch 'main' into feat-374142081-add-source-column-match
chalmerlowe a1eddb5
Update google/cloud/bigquery/external_config.py
chalmerlowe 4ac00ca
updates allowed arg types to include str, and assoc. tests
chalmerlowe 8351a1c
Updates a test to accommodate for strings.
chalmerlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -15,9 +15,10 @@ | ||
| """Classes for load jobs.""" | ||
| import typing | ||
| from typing import FrozenSet, List, Iterable, Optional | ||
| from typing import FrozenSet, List, Iterable, Optional, Union | ||
| from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration | ||
| from google.cloud.bigquery.enums import SourceColumnMatch | ||
| from google.cloud.bigquery.external_config import HivePartitioningOptions | ||
| from google.cloud.bigquery.format_options import ParquetOptions | ||
| from google.cloud.bigquery import _helpers | ||
| @@ -569,6 +570,39 @@ def source_format(self): | ||
| def source_format(self, value): | ||
| self._set_sub_prop("sourceFormat", value) | ||
| @property | ||
| def source_column_match(self) -> Optional[SourceColumnMatch]: | ||
| """Optional[google.cloud.bigquery.enums.SourceColumnMatch]: Controls the | ||
| strategy used to match loaded columns to the schema. If not set, a sensible | ||
| default is chosen based on how the schema is provided. If autodetect is | ||
| used, then columns are matched by name. Otherwise, columns are matched by | ||
| position. This is done to keep the behavior backward-compatible. | ||
| Acceptable values are: | ||
chalmerlowe marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| SOURCE_COLUMN_MATCH_UNSPECIFIED: Unspecified column name match option. | ||
| POSITION: matches by position. This assumes that the columns are ordered | ||
| the same way as the schema. | ||
| NAME: matches by name. This reads the header row as column names and | ||
| reorders columns to match the field names in the schema. | ||
| See: | ||
| https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_column_match | ||
| """ | ||
| value = self._get_sub_prop("sourceColumnMatch") | ||
| return SourceColumnMatch(value) if value is not None else None | ||
| @source_column_match.setter | ||
| def source_column_match(self, value: Union[SourceColumnMatch, str, None]): | ||
| if value is not None and not isinstance(value, (SourceColumnMatch, str)): | ||
| raise TypeError( | ||
| "value must be a google.cloud.bigquery.enums.SourceColumnMatch, str, or None" | ||
| ) | ||
| if isinstance(value, SourceColumnMatch): | ||
| value = value.value | ||
| self._set_sub_prop("sourceColumnMatch", value if value else None) | ||
| @property | ||
| def date_format(self) -> Optional[str]: | ||
| """Optional[str]: Date format used for parsing DATE values. | ||
| @@ -983,6 +1017,13 @@ def clustering_fields(self): | ||
| """ | ||
| return self.configuration.clustering_fields | ||
| @property | ||
| def source_column_match(self) -> Optional[SourceColumnMatch]: | ||
| """See | ||
| :attr:`google.cloud.bigquery.job.LoadJobConfig.source_column_match`. | ||
| """ | ||
| return self.configuration.source_column_match | ||
| @property | ||
| def date_format(self): | ||
| """See | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -844,6 +844,38 @@ def test_write_disposition_setter(self): | ||
| config._properties["load"]["writeDisposition"], write_disposition | ||
| ) | ||
| def test_source_column_match_missing(self): | ||
| config = self._get_target_class()() | ||
| self.assertIsNone(config.source_column_match) | ||
| def test_source_column_match_hit(self): | ||
| from google.cloud.bigquery.enums import SourceColumnMatch | ||
| option_enum = SourceColumnMatch.NAME | ||
| config = self._get_target_class()() | ||
| # Assume API stores the string value of the enum | ||
| config._properties["load"]["sourceColumnMatch"] = option_enum.value | ||
| self.assertEqual(config.source_column_match, option_enum) | ||
| def test_source_column_match_setter(self): | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add another test where we use the setter with a
| ||
| from google.cloud.bigquery.enums import SourceColumnMatch | ||
| option_enum = SourceColumnMatch.POSITION | ||
| config = self._get_target_class()() | ||
| config.source_column_match = option_enum | ||
| # Assert that the string value of the enum is stored | ||
| self.assertEqual( | ||
| config._properties["load"]["sourceColumnMatch"], option_enum.value | ||
| ) | ||
| option_str = "NAME" | ||
| config.source_column_match = option_str | ||
| self.assertEqual(config._properties["load"]["sourceColumnMatch"], option_str) | ||
| def test_source_column_match_setter_invalid_type(self): | ||
| config = self._get_target_class()() | ||
| with self.assertRaises(TypeError): | ||
| config.source_column_match = 3.14 | ||
| def test_date_format_missing(self): | ||
| config = self._get_target_class()() | ||
| self.assertIsNone(config.date_format) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.