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
11 changes: 11 additions & 0 deletions gcloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def insert_data(self,
row_ids=None,
skip_invalid_rows=None,
ignore_unknown_values=None,
template_suffix=None,
client=None):
"""API call: insert table data via a POST request

Expand All @@ -652,6 +653,13 @@ def insert_data(self,
:type ignore_unknown_values: boolean or ``NoneType``
:param ignore_unknown_values: ignore columns beyond schema?

:type template_suffix: string or ``NoneType``
:param template_suffix: treat ``name`` as a template table and provide
a suffix. BigQuery will create the table
``<name> + <template_suffix>`` based on the
schema of the template table. See:
https://cloud.google.com/bigquery/streaming-data-into-bigquery#template-tables

:type client: :class:`gcloud.bigquery.client.Client` or ``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
Expand Down Expand Up @@ -689,6 +697,9 @@ def insert_data(self,
if ignore_unknown_values is not None:
data['ignoreUnknownValues'] = ignore_unknown_values

if template_suffix is not None:
data['templateSuffix'] = template_suffix

response = client.connection.api_request(
method='POST',
path='%s/insertAll' % self.path,
Expand Down
5 changes: 4 additions & 1 deletion gcloud/bigquery/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ def _row_data(row):
SENT = {
'skipInvalidRows': True,
'ignoreUnknownValues': True,
'templateSuffix': '20160303',
'rows': [{'insertId': index, 'json': _row_data(row)}
for index, row in enumerate(ROWS)],
}
Expand All @@ -1194,7 +1195,9 @@ def _row_data(row):
rows=ROWS,
row_ids=[index for index, _ in enumerate(ROWS)],
skip_invalid_rows=True,
ignore_unknown_values=True)
ignore_unknown_values=True,
template_suffix='20160303',
)

self.assertEqual(len(errors), 1)
self.assertEqual(errors[0]['index'], 1)
Expand Down