aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gcp
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2016-04-14 16:57:45 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2016-04-15 09:14:45 -0700
commit7d54db8d490b986bd5b704241d38ff0e28141eac (patch)
tree2c5e3f8db0ebe1210e631251e2b2e4914f6d1a48 /tools/gcp
parentefd9803be5dfb367d0649987136a02be0b70ea0b (diff)
minor refactoring of biq_query_utils
Diffstat (limited to 'tools/gcp')
-rwxr-xr-xtools/gcp/utils/big_query_utils.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/tools/gcp/utils/big_query_utils.py b/tools/gcp/utils/big_query_utils.py
index c331a67942..913afd059e 100755
--- a/tools/gcp/utils/big_query_utils.py
+++ b/tools/gcp/utils/big_query_utils.py
@@ -71,16 +71,22 @@ def create_dataset(biq_query, project_id, dataset_id):
def create_table(big_query, project_id, dataset_id, table_id, table_schema,
description):
+ fields = [{'name': field_name,
+ 'type': field_type,
+ 'description': field_description
+ } for (field_name, field_type, field_description) in table_schema]
+ return create_table2(big_query, project_id, dataset_id, table_id,
+ fields, description)
+
+
+def create_table2(big_query, project_id, dataset_id, table_id, fields_schema,
+ description):
is_success = True
body = {
'description': description,
'schema': {
- 'fields': [{
- 'name': field_name,
- 'type': field_type,
- 'description': field_description
- } for (field_name, field_type, field_description) in table_schema]
+ 'fields': fields_schema
},
'tableReference': {
'datasetId': dataset_id,
@@ -112,9 +118,7 @@ def insert_rows(big_query, project_id, dataset_id, table_id, rows_list):
datasetId=dataset_id,
tableId=table_id,
body=body)
- print body
res = insert_req.execute(num_retries=NUM_RETRIES)
- print res
except HttpError as http_error:
print 'Error in inserting rows in the table %s' % table_id
is_success = False