Skip to content

Commit 926a913

Browse files
committed
feat: adds null_markers as a load and external_config option
1 parent 5711a11 commit 926a913

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

google/cloud/bigquery/external_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,15 @@ def skip_leading_rows(self, value):
476476

477477
@property
478478
def null_markers(self) -> Optional[Iterable[str]]:
479-
"""Optional[Iterable[str]]: The strings that are interpreted as NULL values.
479+
"""Optional[Iterable[str]]: A list of strings represented as SQL NULL values in a CSV file.
480+
481+
.. note::
482+
null_marker and null_markers can't be set at the same time.
483+
If null_marker is set, null_markers has to be not set.
484+
If null_markers is set, null_marker has to be not set.
485+
If both null_marker and null_markers are set at the same time, a user error would be thrown.
486+
Any strings listed in null_markers, including empty string would be interpreted as SQL NULL.
487+
This applies to all column types.
480488
481489
See
482490
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#CsvOptions.FIELDS.null_markers

google/cloud/bigquery/job/load.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,15 @@ def null_marker(self, value):
388388

389389
@property
390390
def null_markers(self) -> Optional[List[str]]:
391-
"""Optional[List[str]]: Represents a null value (CSV only).
391+
"""Optional[List[str]]: A list of strings represented as SQL NULL values in a CSV file.
392+
393+
.. note::
394+
null_marker and null_markers can't be set at the same time.
395+
If null_marker is set, null_markers has to be not set.
396+
If null_markers is set, null_marker has to be not set.
397+
If both null_marker and null_markers are set at the same time, a user error would be thrown.
398+
Any strings listed in null_markers, including empty string would be interpreted as SQL NULL.
399+
This applies to all column types.
392400
393401
See:
394402
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.null_markers

tests/unit/job/test_load.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def _setUpConstants(self):
4242
self.TIME_ZONE = "UTC"
4343
self.TIME_FORMAT = "%H:%M:%S"
4444
self.TIMESTAMP_FORMAT = "YYYY-MM-DD HH:MM:SS.SSSSSSZ"
45+
self.NULL_MARKERS = ["", "NA"]
4546

4647
def _make_resource(self, started=False, ended=False):
4748
resource = super(TestLoadJob, self)._make_resource(started, ended)
@@ -52,6 +53,7 @@ def _make_resource(self, started=False, ended=False):
5253
config["timeZone"] = self.TIME_ZONE
5354
config["timeFormat"] = self.TIME_FORMAT
5455
config["timestampFormat"] = self.TIMESTAMP_FORMAT
56+
config["nullMarkers"] = self.NULL_MARKERS
5557

5658
config["destinationTable"] = {
5759
"projectId": self.PROJECT,
@@ -215,6 +217,7 @@ def test_ctor(self):
215217
self.assertIsNone(job.ignore_unknown_values)
216218
self.assertIsNone(job.max_bad_records)
217219
self.assertIsNone(job.null_marker)
220+
self.assertIsNone(job.null_markers)
218221
self.assertIsNone(job.quote_character)
219222
self.assertIsNone(job.skip_leading_rows)
220223
self.assertIsNone(job.source_format)

0 commit comments

Comments
 (0)