Skip to content
This repository was archived by the owner on Dec 22, 2022. It is now read-only.

Commit 97a55bc

Browse files
committed
Merge pull request tylertreat#95 from hagino3000/add_template_suffix_option
Add template_suffix option support
2 parents c9eb5e4 + bab1c99 commit 97a55bc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

bigquery/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,8 @@ def wait_for_job(self, job, interval=5, timeout=60):
11621162
return job_resource
11631163

11641164
def push_rows(self, dataset, table, rows, insert_id_key=None,
1165-
skip_invalid_rows=None, ignore_unknown_values=None):
1165+
skip_invalid_rows=None, ignore_unknown_values=None,
1166+
template_suffix=None):
11661167
"""Upload rows to BigQuery table.
11671168
11681169
Parameters
@@ -1179,6 +1180,9 @@ def push_rows(self, dataset, table, rows, insert_id_key=None,
11791180
Insert all valid rows of a request, even if invalid rows exist.
11801181
ignore_unknown_values : bool, optional
11811182
Accept rows that contain values that do not match the schema.
1183+
template_suffix : str, optional
1184+
Inserts the rows into an {table}{template_suffix}.
1185+
If table {table}{template_suffix} doesn't exist, create from {table}.
11821186
11831187
Returns
11841188
-------
@@ -1208,6 +1212,9 @@ def push_rows(self, dataset, table, rows, insert_id_key=None,
12081212
if ignore_unknown_values is not None:
12091213
data['ignoreUnknownValues'] = ignore_unknown_values
12101214

1215+
if template_suffix is not None:
1216+
data['templateSuffix'] = template_suffix
1217+
12111218
try:
12121219
response = table_data.insertAll(
12131220
projectId=self.project_id,

bigquery/tests/test_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,9 +2176,12 @@ def test_request_data_with_options(self):
21762176
self.dataset, self.table, self.rows,
21772177
insert_id_key='one',
21782178
ignore_unknown_values=True,
2179-
skip_invalid_rows=True)
2179+
skip_invalid_rows=True,
2180+
template_suffix='20160428'
2181+
)
21802182
expected_body['ignoreUnknownValues'] = True
21812183
expected_body['skipInvalidRows'] = True
2184+
expected_body['templateSuffix'] = '20160428'
21822185
self.mock_table_data.insertAll.assert_called_with(
21832186
projectId=self.project,
21842187
datasetId=self.dataset,

0 commit comments

Comments
 (0)