From bab1c997ea4b40ee84dc341a6bc10022380311e1 Mon Sep 17 00:00:00 2001 From: Takashi Nishibayashi Date: Thu, 28 Apr 2016 15:02:06 +0900 Subject: [PATCH] Add template_suffix option support --- bigquery/client.py | 9 ++++++++- bigquery/tests/test_client.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bigquery/client.py b/bigquery/client.py index 9bab750..ea5c503 100644 --- a/bigquery/client.py +++ b/bigquery/client.py @@ -1162,7 +1162,8 @@ def wait_for_job(self, job, interval=5, timeout=60): return job_resource def push_rows(self, dataset, table, rows, insert_id_key=None, - skip_invalid_rows=None, ignore_unknown_values=None): + skip_invalid_rows=None, ignore_unknown_values=None, + template_suffix=None): """Upload rows to BigQuery table. Parameters @@ -1179,6 +1180,9 @@ def push_rows(self, dataset, table, rows, insert_id_key=None, Insert all valid rows of a request, even if invalid rows exist. ignore_unknown_values : bool, optional Accept rows that contain values that do not match the schema. + template_suffix : str, optional + Inserts the rows into an {table}{template_suffix}. + If table {table}{template_suffix} doesn't exist, create from {table}. Returns ------- @@ -1208,6 +1212,9 @@ def push_rows(self, dataset, table, rows, insert_id_key=None, if ignore_unknown_values is not None: data['ignoreUnknownValues'] = ignore_unknown_values + if template_suffix is not None: + data['templateSuffix'] = template_suffix + try: response = table_data.insertAll( projectId=self.project_id, diff --git a/bigquery/tests/test_client.py b/bigquery/tests/test_client.py index ffd7818..39bf05b 100644 --- a/bigquery/tests/test_client.py +++ b/bigquery/tests/test_client.py @@ -2176,9 +2176,12 @@ def test_request_data_with_options(self): self.dataset, self.table, self.rows, insert_id_key='one', ignore_unknown_values=True, - skip_invalid_rows=True) + skip_invalid_rows=True, + template_suffix='20160428' + ) expected_body['ignoreUnknownValues'] = True expected_body['skipInvalidRows'] = True + expected_body['templateSuffix'] = '20160428' self.mock_table_data.insertAll.assert_called_with( projectId=self.project, datasetId=self.dataset,