Skip to content

Commit 0d74392

Browse files
committed
renames some attributes and adds some typehinting
1 parent 13ccbe7 commit 0d74392

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

google/cloud/bigquery/enums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ class JobCreationMode(object):
467467
class SourceColumnMatch(str, enum.Enum):
468468
"""Uses sensible defaults based on how the schema is provided.
469469
470-
If autodetect is used, then columns are matched by name. Otherwise, columns
471-
are matched by position. This is done to keep the behavior backward-compati
472-
ble.
470+
If autodetect is used, then columns are matched by name. Otherwise, columns
471+
are matched by position. This is done to keep the behavior backward-compati
472+
ble.
473473
"""
474474

475475
SOURCE_COLUMN_MATCH_UNSPECIFIED = "SOURCE_COLUMN_MATCH_UNSPECIFIED"

google/cloud/bigquery/external_config.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ def source_column_match(self) -> Optional[str]:
514514
See
515515
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.source_column_match
516516
"""
517-
return self._properties.get("sourceColumnMatch")
517+
result = self._properties.get("sourceColumnMatch")
518+
return typing.cast(str, result)
518519

519520
@source_column_match.setter
520521
def source_column_match(self, value: Optional[str]):
@@ -904,7 +905,9 @@ def time_zone(self) -> Optional[str]:
904905
See:
905906
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.time_zone
906907
"""
907-
return self._properties.get("timeZone")
908+
909+
result = self._properties.get("timeZone")
910+
return typing.cast(str, result)
908911

909912
@time_zone.setter
910913
def time_zone(self, value: Optional[str]):
@@ -919,7 +922,8 @@ def date_format(self) -> Optional[str]:
919922
See:
920923
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.date_format
921924
"""
922-
return self._properties.get("dateFormat")
925+
result = self._properties.get("dateFormat")
926+
return typing.cast(str, result)
923927

924928
@date_format.setter
925929
def date_format(self, value: Optional[str]):
@@ -934,7 +938,8 @@ def datetime_format(self) -> Optional[str]:
934938
See:
935939
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.datetime_format
936940
"""
937-
return self._properties.get("datetimeFormat")
941+
result = self._properties.get("datetimeFormat")
942+
return typing.cast(str, result)
938943

939944
@datetime_format.setter
940945
def datetime_format(self, value: Optional[str]):
@@ -949,7 +954,8 @@ def time_format(self) -> Optional[str]:
949954
See:
950955
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.time_format
951956
"""
952-
return self._properties.get("timeFormat")
957+
result = self._properties.get("timeFormat")
958+
return typing.cast(str, result)
953959

954960
@time_format.setter
955961
def time_format(self, value: Optional[str]):
@@ -964,7 +970,8 @@ def timestamp_format(self) -> Optional[str]:
964970
See:
965971
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.timestamp_format
966972
"""
967-
return self._properties.get("timestampFormat")
973+
result = self._properties.get("timestampFormat")
974+
return typing.cast(str, result)
968975

969976
@timestamp_format.setter
970977
def timestamp_format(self, value: Optional[str]):

google/cloud/bigquery/job/load.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ def source_column_match(self) -> Optional[SourceColumnMatch]:
655655
reorders columns to match the field names in the schema.
656656
657657
See:
658-
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_column_match_strategy
658+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_column_match
659659
"""
660-
value = self._get_sub_prop("sourceColumnMatchStrategy")
660+
value = self._get_sub_prop("sourceColumnMatch")
661661
if value is not None:
662662
return SourceColumnMatch(value)
663663
return None
@@ -668,7 +668,7 @@ def source_column_match(self, value: Optional[SourceColumnMatch]):
668668
raise TypeError(
669669
"value must be a google.cloud.bigquery.enums.SourceColumnMatch or None"
670670
)
671-
self._set_sub_prop("sourceColumnMatchStrategy", value.value if value else None)
671+
self._set_sub_prop("sourceColumnMatch", value.value if value else None)
672672

673673
@property
674674
def time_partitioning(self):
@@ -1054,11 +1054,11 @@ def null_markers(self):
10541054
return self.configuration.null_markers
10551055

10561056
@property
1057-
def source_column_match_strategy(self):
1057+
def source_column_match(self):
10581058
"""See
1059-
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_column_match_strategy`.
1059+
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_column_match`.
10601060
"""
1061-
return self.configuration.source_column_match_strategy
1061+
return self.configuration.source_column_match
10621062

10631063
@property
10641064
def schema_update_options(self):

tests/unit/job/test_load.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ def test_reload_w_bound_client(self):
815815
query_params={"projection": "full"},
816816
timeout=DEFAULT_GET_JOB_TIMEOUT,
817817
)
818+
print(f"DINOSAUR:\n{job}\n{RESOURCE}")
818819
self._verifyResourceProperties(job, RESOURCE)
819820

820821
def test_reload_w_alternate_client(self):

tests/unit/test_external_config.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def test_to_api_repr_hive_partitioning(self):
264264
self.assertEqual(got_resource, expected_resource)
265265

266266
NULL_MARKERS = ["", "N/A"]
267-
SOURCE_COLUMN_NAME_MATCH_OPTION = "NAME"
267+
SOURCE_COLUMN_MATCH = "NAME"
268268

269269
def test_from_api_repr_csv(self):
270270
resource = _copy_and_update(
@@ -280,7 +280,7 @@ def test_from_api_repr_csv(self):
280280
"encoding": "encoding",
281281
"preserveAsciiControlCharacters": False,
282282
"nullMarkers": self.NULL_MARKERS,
283-
"sourceColumnMatch": self.SOURCE_COLUMN_NAME_MATCH_OPTION,
283+
"sourceColumnMatch": self.SOURCE_COLUMN_MATCH,
284284
},
285285
},
286286
)
@@ -299,8 +299,8 @@ def test_from_api_repr_csv(self):
299299
self.assertEqual(ec.options.preserve_ascii_control_characters, False)
300300
self.assertEqual(ec.options.null_markers, self.NULL_MARKERS)
301301
self.assertEqual(
302-
ec.options.source_column_name_match_option,
303-
self.SOURCE_COLUMN_NAME_MATCH_OPTION,
302+
ec.options.source_column_match,
303+
self.SOURCE_COLUMN_MATCH,
304304
)
305305

306306
got_resource = ec.to_api_repr()
@@ -324,9 +324,7 @@ def test_to_api_repr_csv(self):
324324
options.allow_jagged_rows = False
325325
options.preserve_ascii_control_characters = False
326326
options.null_markers = self.NULL_MARKERS
327-
options.source_column_name_match_option = (
328-
self.SOURCE_COLUMN_NAME_MATCH_OPTION
329-
)
327+
options.source_column_match = self.SOURCE_COLUMN_MATCH
330328
ec.csv_options = options
331329

332330
exp_resource = {
@@ -340,7 +338,7 @@ def test_to_api_repr_csv(self):
340338
"encoding": "encoding",
341339
"preserveAsciiControlCharacters": False,
342340
"nullMarkers": self.NULL_MARKERS,
343-
"sourceColumnMatch": self.SOURCE_COLUMN_NAME_MATCH_OPTION,
341+
"sourceColumnMatch": self.SOURCE_COLUMN_MATCH,
344342
},
345343
}
346344

@@ -903,7 +901,7 @@ def test_to_api_repr(self):
903901
options.encoding = "UTF-8"
904902
options.preserve_ascii_control_characters = False
905903
options.null_markers = ["NA"]
906-
options.source_column_name_match_option = "POSITION"
904+
options.source_column_match = "POSITION"
907905

908906
resource = options.to_api_repr()
909907

0 commit comments

Comments
 (0)