Skip to content

Commit a9b187f

Browse files
committed
Adds enum, revises some docstrings, and attribute names
1 parent bd75b96 commit a9b187f

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

google/cloud/bigquery/enums.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,22 @@ class JobCreationMode(object):
462462
The conditions under which BigQuery can decide to not create a Job are
463463
subject to change.
464464
"""
465+
466+
467+
class SourceColumnMatch(str, enum.Enum):
468+
"""Uses sensible defaults based on how the schema is provided.
469+
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-compatible.
472+
"""
473+
474+
SOURCE_COLUMN_MATCH_UNSPECIFIED = "SOURCE_COLUMN_MATCH_UNSPECIFIED"
475+
"""Unspecified column name match option."""
476+
477+
POSITION = "POSITION"
478+
"""Matches by position. This assumes that the columns are ordered the same
479+
way as the schema."""
480+
481+
NAME = "NAME"
482+
"""Matches by name. This reads the header row as column names and reorders
483+
columns to match the field names in the schema."""

google/cloud/bigquery/external_config.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,19 @@ def skip_leading_rows(self, value):
476476

477477
@property
478478
def null_markers(self) -> Optional[List[str]]:
479-
"""Optional[List[str]]: A list of strings represented as SQL NULL value.
479+
"""Optional[List[str]]: A list of strings represented as SQL NULL value in a CSV file.
480+
481+
null_marker and null_markers can't be set at the same time.
482+
If null_marker is set, null_markers has to be not set.
483+
If null_markers is set, null_marker has to be not set.
484+
If both null_marker and null_markers are set at the same time, a user
485+
error would be thrown.
486+
Any strings listed in null_markers, including
487+
empty string would be interpreted as SQL NULL. This applies to all column
488+
types.
480489
481490
See
482-
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#CsvOptions.FIELDS.null_marker
483-
(Note: API doc refers to null_marker singular, but proto is null_markers plural and a list)
491+
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#CsvOptions.FIELDS.null_markers
484492
"""
485493
return self._properties.get("nullMarkers")
486494

@@ -490,13 +498,19 @@ def null_markers(self, value: Optional[List[str]]):
490498

491499
@property
492500
def source_column_name_match_option(self) -> Optional[str]:
493-
"""Optional[str]: Controls the strategy used to match loaded columns to the schema.
494-
Acceptable values are: "POSITION", "NAME".
501+
"""Optional[str]: Controls the strategy used to match loaded columns to the schema. If not
502+
set, a sensible default is chosen based on how the schema is provided. If
503+
autodetect is used, then columns are matched by name. Otherwise, columns
504+
are matched by position. This is done to keep the behavior
505+
backward-compatible.
506+
Acceptable values are:
507+
POSITION - matches by position. This assumes that the columns are ordered
508+
the same way as the schema.
509+
NAME - matches by name. This reads the header row as column names and
510+
reorders columns to match the field names in the schema.
495511
496512
See
497513
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.source_column_match
498-
(Note: This field is documented under ExternalDataConfiguration in the REST API docs but seems
499-
more appropriate here for CSVOptions, matching the proto structure for external tables)
500514
"""
501515
return self._properties.get("sourceColumnMatch")
502516

tests/unit/job/test_load.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _setUpConstants(self):
4242
self.DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
4343
self.TIME_FORMAT = "%H:%M:%S"
4444
self.TIMESTAMP_FORMAT = "YYYY-MM-DD HH:MM:SS.SSSSSSZ"
45-
self.NULL_MARKERS = ["N/A", "\\N"]
45+
self.NULL_MARKERS = ["N/A", "NA"]
4646
self.SOURCE_COLUMN_NAME_MATCH_OPTION = "MATCH_BY_NAME"
4747

4848
def _make_resource(self, started=False, ended=False):

0 commit comments

Comments
 (0)