Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ def upload_from_file(self,
skip_leading_rows=None,
write_disposition=None,
client=None,
job_name=None):
job_name=None,
null_marker=None):
"""Upload the contents of this table from a file-like object.

:type file_obj: file
Expand Down Expand Up @@ -1116,6 +1117,9 @@ def upload_from_file(self,
:param job_name: Optional. The id of the job. Generated if not
explicitly passed in.

:type null_marker: str
:param null_marker: Optional. A custom null marker (example: "\\N")

:rtype: :class:`~google.cloud.bigquery.jobs.LoadTableFromStorageJob`

:returns: the job instance used to load the data (e.g., for
Expand All @@ -1135,7 +1139,7 @@ def upload_from_file(self,
encoding, field_delimiter,
ignore_unknown_values, max_bad_records,
quote_character, skip_leading_rows,
write_disposition, job_name)
write_disposition, job_name, null_marker)

try:
created_json = self._do_upload(
Expand All @@ -1157,7 +1161,8 @@ def _configure_job_metadata(metadata, # pylint: disable=too-many-arguments
quote_character,
skip_leading_rows,
write_disposition,
job_name):
job_name,
null_marker):
"""Helper for :meth:`Table.upload_from_file`."""
load_config = metadata['configuration']['load']

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

if null_marker is not None:
load_config['nullMarker'] = null_marker


def _parse_schema_resource(info):
"""Parse a resource fragment into a schema field.
Expand Down
12 changes: 7 additions & 5 deletions bigquery/tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,8 @@ def test_upload_file_resumable_metadata(self):
'quote_character': '"',
'skip_leading_rows': 1,
'write_disposition': 'WRITE_APPEND',
'job_name': 'oddjob'
'job_name': 'oddjob',
'null_marker': r'\N',
}

expected_config = {
Expand All @@ -1878,7 +1879,7 @@ def test_upload_file_resumable_metadata(self):
'destinationTable': {
'projectId': table._dataset._client.project,
'datasetId': table.dataset_name,
'tableId': table.name
'tableId': table.name,
},
'allowJaggedRows': config_args['allow_jagged_rows'],
'allowQuotedNewlines':
Expand All @@ -1892,9 +1893,10 @@ def test_upload_file_resumable_metadata(self):
'quote': config_args['quote_character'],
'skipLeadingRows': config_args['skip_leading_rows'],
'writeDisposition': config_args['write_disposition'],
'jobReference': {'jobId': config_args['job_name']}
}
}
'jobReference': {'jobId': config_args['job_name']},
'nullMarker': config_args['null_marker'],
},
},
}

do_upload_patch = self._make_do_upload_patch(
Expand Down