diff --git a/gcloud/bigquery/table.py b/gcloud/bigquery/table.py index dd8e003bc8d5..bbe1f1ccfdf9 100644 --- a/gcloud/bigquery/table.py +++ b/gcloud/bigquery/table.py @@ -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 @@ -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 + `` + `` 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. @@ -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, diff --git a/gcloud/bigquery/test_table.py b/gcloud/bigquery/test_table.py index 56c9416fc5cf..2069d2455fc2 100644 --- a/gcloud/bigquery/test_table.py +++ b/gcloud/bigquery/test_table.py @@ -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)], } @@ -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)