Skip to content

Commit 69dc45a

Browse files
Add support for a custom null marker. (#3776)
1 parent 1fcc1a4 commit 69dc45a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

bigquery/google/cloud/bigquery/table.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ def upload_from_file(self,
10431043
skip_leading_rows=None,
10441044
write_disposition=None,
10451045
client=None,
1046-
job_name=None):
1046+
job_name=None,
1047+
null_marker=None):
10471048
"""Upload the contents of this table from a file-like object.
10481049
10491050
:type file_obj: file
@@ -1116,6 +1117,9 @@ def upload_from_file(self,
11161117
:param job_name: Optional. The id of the job. Generated if not
11171118
explicitly passed in.
11181119
1120+
:type null_marker: str
1121+
:param null_marker: Optional. A custom null marker (example: "\\N")
1122+
11191123
:rtype: :class:`~google.cloud.bigquery.jobs.LoadTableFromStorageJob`
11201124
11211125
:returns: the job instance used to load the data (e.g., for
@@ -1135,7 +1139,7 @@ def upload_from_file(self,
11351139
encoding, field_delimiter,
11361140
ignore_unknown_values, max_bad_records,
11371141
quote_character, skip_leading_rows,
1138-
write_disposition, job_name)
1142+
write_disposition, job_name, null_marker)
11391143

11401144
try:
11411145
created_json = self._do_upload(
@@ -1157,7 +1161,8 @@ def _configure_job_metadata(metadata, # pylint: disable=too-many-arguments
11571161
quote_character,
11581162
skip_leading_rows,
11591163
write_disposition,
1160-
job_name):
1164+
job_name,
1165+
null_marker):
11611166
"""Helper for :meth:`Table.upload_from_file`."""
11621167
load_config = metadata['configuration']['load']
11631168

@@ -1194,6 +1199,9 @@ def _configure_job_metadata(metadata, # pylint: disable=too-many-arguments
11941199
if job_name is not None:
11951200
load_config['jobReference'] = {'jobId': job_name}
11961201

1202+
if null_marker is not None:
1203+
load_config['nullMarker'] = null_marker
1204+
11971205

11981206
def _parse_schema_resource(info):
11991207
"""Parse a resource fragment into a schema field.

bigquery/tests/unit/test_table.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,8 @@ def test_upload_file_resumable_metadata(self):
18681868
'quote_character': '"',
18691869
'skip_leading_rows': 1,
18701870
'write_disposition': 'WRITE_APPEND',
1871-
'job_name': 'oddjob'
1871+
'job_name': 'oddjob',
1872+
'null_marker': r'\N',
18721873
}
18731874

18741875
expected_config = {
@@ -1878,7 +1879,7 @@ def test_upload_file_resumable_metadata(self):
18781879
'destinationTable': {
18791880
'projectId': table._dataset._client.project,
18801881
'datasetId': table.dataset_name,
1881-
'tableId': table.name
1882+
'tableId': table.name,
18821883
},
18831884
'allowJaggedRows': config_args['allow_jagged_rows'],
18841885
'allowQuotedNewlines':
@@ -1892,9 +1893,10 @@ def test_upload_file_resumable_metadata(self):
18921893
'quote': config_args['quote_character'],
18931894
'skipLeadingRows': config_args['skip_leading_rows'],
18941895
'writeDisposition': config_args['write_disposition'],
1895-
'jobReference': {'jobId': config_args['job_name']}
1896-
}
1897-
}
1896+
'jobReference': {'jobId': config_args['job_name']},
1897+
'nullMarker': config_args['null_marker'],
1898+
},
1899+
},
18981900
}
18991901

19001902
do_upload_patch = self._make_do_upload_patch(

0 commit comments

Comments
 (0)