Skip to content

Commit 13ccbe7

Browse files
committed
updates branch with a number of minor tweaks
1 parent d721ea4 commit 13ccbe7

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

google/cloud/bigquery/external_config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ def skip_leading_rows(self):
474474
def skip_leading_rows(self, value):
475475
self._properties["skipLeadingRows"] = str(value)
476476

477+
# TODO: null_marker needs to be added to this code base.
478+
477479
@property
478480
def null_markers(self) -> Optional[List[str]]:
479481
"""Optional[List[str]]: A list of strings represented as SQL NULL value in a CSV file.
@@ -497,7 +499,7 @@ def null_markers(self, value: Optional[List[str]]):
497499
self._properties["nullMarkers"] = value
498500

499501
@property
500-
def source_column_name_match_option(self) -> Optional[str]:
502+
def source_column_match(self) -> Optional[str]:
501503
"""Optional[str]: Controls the strategy used to match loaded columns to the schema. If not
502504
set, a sensible default is chosen based on how the schema is provided. If
503505
autodetect is used, then columns are matched by name. Otherwise, columns
@@ -514,8 +516,8 @@ def source_column_name_match_option(self) -> Optional[str]:
514516
"""
515517
return self._properties.get("sourceColumnMatch")
516518

517-
@source_column_name_match_option.setter
518-
def source_column_name_match_option(self, value: Optional[str]):
519+
@source_column_match.setter
520+
def source_column_match(self, value: Optional[str]):
519521
self._properties["sourceColumnMatch"] = value
520522

521523
def to_api_repr(self) -> dict:

google/cloud/bigquery/job/load.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,6 @@ def timestamp_format(self, value: Optional[str]):
624624
def null_markers(self) -> Optional[List[str]]:
625625
"""Optional[List[str]]: A list of strings represented as SQL NULL value in a CSV file.
626626
627-
(CSV only).
628-
629627
null_marker and null_markers can't be set at the same time.
630628
If null_marker is set, null_markers has to be not set.
631629
If null_markers is set, null_marker has to be not set.
@@ -645,14 +643,16 @@ def null_markers(self, value: Optional[List[str]]):
645643
self._set_sub_prop("nullMarkers", value)
646644

647645
@property
648-
def source_column_match_strategy(self) -> Optional[SourceColumnMatch]:
649-
"""Optional[google.cloud.bigquery.enums.SourceColumnMatch]: Controls the strategy
650-
used to match loaded columns to the schema. If not set, a sensible default is
651-
chosen based on how the schema is provided. If autodetect is used, then
652-
columns are matched by name. Otherwise, columns are matched by position.
653-
This is done to keep the behavior backward-compatible.
654-
655-
(CSV only).
646+
def source_column_match(self) -> Optional[SourceColumnMatch]:
647+
"""Optional[google.cloud.bigquery.enums.SourceColumnMatch]: Controls the strategy used to match
648+
loaded columns to the schema. If not set, a sensible default is chosen based on how the schema
649+
is provided. If autodetect is used, then columns are matched by name. Otherwise, columns
650+
are matched by position. This is done to keep the behavior backward-compatible.
651+
Acceptable values are:
652+
POSITION - matches by position. This assumes that the columns are ordered
653+
the same way as the schema.
654+
NAME - matches by name. This reads the header row as column names and
655+
reorders columns to match the field names in the schema.
656656
657657
See:
658658
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_column_match_strategy
@@ -662,8 +662,8 @@ def source_column_match_strategy(self) -> Optional[SourceColumnMatch]:
662662
return SourceColumnMatch(value)
663663
return None
664664

665-
@source_column_match_strategy.setter
666-
def source_column_match_strategy(self, value: Optional[SourceColumnMatch]):
665+
@source_column_match.setter
666+
def source_column_match(self, value: Optional[SourceColumnMatch]):
667667
if value is not None and not isinstance(value, SourceColumnMatch):
668668
raise TypeError(
669669
"value must be a google.cloud.bigquery.enums.SourceColumnMatch or None"

tests/unit/job/test_load.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _setUpConstants(self):
4343
self.TIME_FORMAT = "%H:%M:%S"
4444
self.TIMESTAMP_FORMAT = "YYYY-MM-DD HH:MM:SS.SSSSSSZ"
4545
self.NULL_MARKERS = ["N/A", "NA"]
46-
self.SOURCE_COLUMN_NAME_MATCH_OPTION = "NAME" # Corrected to actual enum value
46+
self.SOURCE_COLUMN_MATCH = "NAME"
4747

4848
def _make_resource(self, started=False, ended=False):
4949
resource = super(TestLoadJob, self)._make_resource(started, ended)
@@ -55,7 +55,9 @@ def _make_resource(self, started=False, ended=False):
5555
config["timeFormat"] = self.TIME_FORMAT
5656
config["timestampFormat"] = self.TIMESTAMP_FORMAT
5757
config["nullMarkers"] = self.NULL_MARKERS
58-
config["sourceColumnMatchStrategy"] = self.SOURCE_COLUMN_NAME_MATCH_OPTION # Keep value as string for mock API repr
58+
config[
59+
"sourceColumnMatch"
60+
] = self.SOURCE_COLUMN_MATCH # Keep value as string for mock API repr
5961
config["destinationTable"] = {
6062
"projectId": self.PROJECT,
6163
"datasetId": self.DS_ID,
@@ -191,14 +193,14 @@ def _verifyResourceProperties(self, job, resource):
191193
self.assertEqual(job.null_markers, config["nullMarkers"])
192194
else:
193195
self.assertIsNone(job.null_markers)
194-
if "sourceColumnMatchStrategy" in config:
195-
# job.source_column_match_strategy will be an Enum, config[...] is a string
196+
if "sourceColumnMatch" in config:
197+
# job.source_column_match will be an Enum, config[...] is a string
196198
self.assertEqual(
197-
job.source_column_match_strategy.value,
198-
config["sourceColumnMatchStrategy"],
199+
job.source_column_match.value,
200+
config["sourceColumnMatch"],
199201
)
200202
else:
201-
self.assertIsNone(job.source_column_match_strategy)
203+
self.assertIsNone(job.source_column_match)
202204

203205
def test_ctor(self):
204206
client = _make_client(project=self.PROJECT)
@@ -247,7 +249,7 @@ def test_ctor(self):
247249
self.assertIsNone(job.time_format)
248250
self.assertIsNone(job.timestamp_format)
249251
self.assertIsNone(job.null_markers)
250-
self.assertIsNone(job.source_column_match_strategy)
252+
self.assertIsNone(job.source_column_match)
251253

252254
def test_ctor_w_config(self):
253255
from google.cloud.bigquery.schema import SchemaField
@@ -631,7 +633,7 @@ def test_begin_w_alternate_client(self):
631633
"timeFormat": self.TIME_FORMAT,
632634
"timestampFormat": self.TIMESTAMP_FORMAT,
633635
"nullMarkers": self.NULL_MARKERS,
634-
"sourceColumnMatchStrategy": self.SOURCE_COLUMN_NAME_MATCH_OPTION, # Keep value as string for mock API repr
636+
"sourceColumnMatch": self.SOURCE_COLUMN_MATCH,
635637
}
636638
RESOURCE["configuration"]["load"] = LOAD_CONFIGURATION
637639
conn1 = make_connection()
@@ -668,7 +670,8 @@ def test_begin_w_alternate_client(self):
668670
config.null_markers = self.NULL_MARKERS
669671
# Ensure we are setting with the Enum type if that's what the setter expects
670672
from google.cloud.bigquery.enums import SourceColumnMatch
671-
config.source_column_match_strategy = SourceColumnMatch(self.SOURCE_COLUMN_NAME_MATCH_OPTION)
673+
674+
config.source_column_match = SourceColumnMatch(self.SOURCE_COLUMN_MATCH)
672675
with mock.patch(
673676
"google.cloud.bigquery.opentelemetry_tracing._get_final_span_attributes"
674677
) as final_attributes:

tests/unit/job/test_load_config.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,9 @@ def test_timestamp_format_setter(self):
906906
timestamp_format = "YYYY/MM/DD HH24:MI:SS.FF6 TZR"
907907
config = self._get_target_class()()
908908
config.timestamp_format = timestamp_format
909-
self.assertEqual(config._properties["load"]["timestampFormat"], timestamp_format)
909+
self.assertEqual(
910+
config._properties["load"]["timestampFormat"], timestamp_format
911+
)
910912

911913
def test_null_markers_missing(self):
912914
config = self._get_target_class()()
@@ -924,34 +926,34 @@ def test_null_markers_setter(self):
924926
config.null_markers = null_markers
925927
self.assertEqual(config._properties["load"]["nullMarkers"], null_markers)
926928

927-
def test_source_column_match_strategy_missing(self):
929+
def test_source_column_match_missing(self):
928930
config = self._get_target_class()()
929-
self.assertIsNone(config.source_column_match_strategy)
931+
self.assertIsNone(config.source_column_match)
930932

931-
def test_source_column_match_strategy_hit(self):
933+
def test_source_column_match_hit(self):
932934
from google.cloud.bigquery.enums import SourceColumnMatch
933935

934936
option_enum = SourceColumnMatch.NAME
935937
config = self._get_target_class()()
936938
# Assume API stores the string value of the enum
937-
config._properties["load"]["sourceColumnMatchStrategy"] = option_enum.value
938-
self.assertEqual(config.source_column_match_strategy, option_enum)
939+
config._properties["load"]["sourceColumnMatch"] = option_enum.value
940+
self.assertEqual(config.source_column_match, option_enum)
939941

940-
def test_source_column_match_strategy_setter(self):
942+
def test_source_column_match_setter(self):
941943
from google.cloud.bigquery.enums import SourceColumnMatch
942944

943945
option_enum = SourceColumnMatch.POSITION
944946
config = self._get_target_class()()
945-
config.source_column_match_strategy = option_enum
947+
config.source_column_match = option_enum
946948
# Assert that the string value of the enum is stored
947949
self.assertEqual(
948-
config._properties["load"]["sourceColumnMatchStrategy"], option_enum.value
950+
config._properties["load"]["sourceColumnMatch"], option_enum.value
949951
)
950952

951-
def test_source_column_match_strategy_setter_invalid_type(self):
953+
def test_source_column_match_setter_invalid_type(self):
952954
config = self._get_target_class()()
953955
with self.assertRaises(TypeError):
954-
config.source_column_match_strategy = "INVALID_STRING_TYPE"
956+
config.source_column_match = "INVALID_STRING_TYPE"
955957

956958
def test_parquet_options_missing(self):
957959
config = self._get_target_class()()

0 commit comments

Comments
 (0)