This is an automated email from the ASF dual-hosted git repository.
goenka pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new abad054 [BEAM-7856] Re Raise exception for code other than 409
new 6486fcf Merge pull request #9396 from angoenka/fix_bq_exception
abad054 is described below
commit abad05469c0fd0ca5e47bb3be03ad22cc93ca02d
Author: Ankur Goenka <[email protected]>
AuthorDate: Wed Aug 21 15:53:51 2019 -0700
[BEAM-7856] Re Raise exception for code other than 409
---
sdks/python/apache_beam/io/gcp/bigquery_tools.py | 2 ++
sdks/python/apache_beam/io/gcp/bigquery_tools_test.py | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/sdks/python/apache_beam/io/gcp/bigquery_tools.py
b/sdks/python/apache_beam/io/gcp/bigquery_tools.py
index 8211e28..9f30d5f 100644
--- a/sdks/python/apache_beam/io/gcp/bigquery_tools.py
+++ b/sdks/python/apache_beam/io/gcp/bigquery_tools.py
@@ -672,6 +672,8 @@ class BigQueryWrapper(object):
logging.debug('Skipping Creation. Table %s:%s.%s already exists.'
% (project_id, dataset_id, table_id))
created_table = self.get_table(project_id, dataset_id, table_id)
+ else:
+ raise
logging.info('Created table %s.%s.%s with schema %s. '
'Result: %s.',
project_id, dataset_id, table_id,
diff --git a/sdks/python/apache_beam/io/gcp/bigquery_tools_test.py
b/sdks/python/apache_beam/io/gcp/bigquery_tools_test.py
index cdcba22..ecc0185 100644
--- a/sdks/python/apache_beam/io/gcp/bigquery_tools_test.py
+++ b/sdks/python/apache_beam/io/gcp/bigquery_tools_test.py
@@ -179,6 +179,21 @@ class TestBigQueryWrapper(unittest.TestCase):
mode='REQUIRED')]), False, False)
self.assertEqual(new_table, 'table_id')
+ def test_get_or_create_table_intermittent_exception(self):
+ client = mock.Mock()
+ client.tables.Insert.side_effect = [
+ HttpError(response={'status': '408'}, url='', content=''), 'table_id'
+ ]
+ client.tables.Get.side_effect = [None, 'table_id']
+ wrapper = beam.io.gcp.bigquery_tools.BigQueryWrapper(client)
+ new_table = wrapper.get_or_create_table(
+ 'project_id', 'dataset_id', 'table_id',
+ bigquery.TableSchema(fields=[
+ bigquery.TableFieldSchema(
+ name='b', type='BOOLEAN', mode='REQUIRED')
+ ]), False, False)
+ self.assertEqual(new_table, 'table_id')
+
@unittest.skipIf(HttpError is None, 'GCP dependencies are not installed')
class TestBigQueryReader(unittest.TestCase):