|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#!/usr/bin/env python2.7 |
|
|
|
|
|
|
|
|
|
from __future__ import print_function |
|
|
|
|
import argparse |
|
|
|
|
import json |
|
|
|
|
import uuid |
|
|
|
@ -37,11 +38,11 @@ def create_dataset(biq_query, project_id, dataset_id): |
|
|
|
|
dataset_req.execute(num_retries=NUM_RETRIES) |
|
|
|
|
except HttpError as http_error: |
|
|
|
|
if http_error.resp.status == 409: |
|
|
|
|
print 'Warning: The dataset %s already exists' % dataset_id |
|
|
|
|
print('Warning: The dataset %s already exists' % dataset_id) |
|
|
|
|
else: |
|
|
|
|
# Note: For more debugging info, print "http_error.content" |
|
|
|
|
print 'Error in creating dataset: %s. Err: %s' % (dataset_id, |
|
|
|
|
http_error) |
|
|
|
|
print('Error in creating dataset: %s. Err: %s' % (dataset_id, |
|
|
|
|
http_error)) |
|
|
|
|
is_success = False |
|
|
|
|
return is_success |
|
|
|
|
|
|
|
|
@ -109,13 +110,13 @@ def create_table2(big_query, |
|
|
|
|
table_req = big_query.tables().insert( |
|
|
|
|
projectId=project_id, datasetId=dataset_id, body=body) |
|
|
|
|
res = table_req.execute(num_retries=NUM_RETRIES) |
|
|
|
|
print 'Successfully created %s "%s"' % (res['kind'], res['id']) |
|
|
|
|
print('Successfully created %s "%s"' % (res['kind'], res['id'])) |
|
|
|
|
except HttpError as http_error: |
|
|
|
|
if http_error.resp.status == 409: |
|
|
|
|
print 'Warning: Table %s already exists' % table_id |
|
|
|
|
print('Warning: Table %s already exists' % table_id) |
|
|
|
|
else: |
|
|
|
|
print 'Error in creating table: %s. Err: %s' % (table_id, |
|
|
|
|
http_error) |
|
|
|
|
print('Error in creating table: %s. Err: %s' % (table_id, |
|
|
|
|
http_error)) |
|
|
|
|
is_success = False |
|
|
|
|
return is_success |
|
|
|
|
|
|
|
|
@ -141,9 +142,9 @@ def patch_table(big_query, project_id, dataset_id, table_id, fields_schema): |
|
|
|
|
tableId=table_id, |
|
|
|
|
body=body) |
|
|
|
|
res = table_req.execute(num_retries=NUM_RETRIES) |
|
|
|
|
print 'Successfully patched %s "%s"' % (res['kind'], res['id']) |
|
|
|
|
print('Successfully patched %s "%s"' % (res['kind'], res['id'])) |
|
|
|
|
except HttpError as http_error: |
|
|
|
|
print 'Error in creating table: %s. Err: %s' % (table_id, http_error) |
|
|
|
|
print('Error in creating table: %s. Err: %s' % (table_id, http_error)) |
|
|
|
|
is_success = False |
|
|
|
|
return is_success |
|
|
|
|
|
|
|
|
@ -159,10 +160,10 @@ def insert_rows(big_query, project_id, dataset_id, table_id, rows_list): |
|
|
|
|
body=body) |
|
|
|
|
res = insert_req.execute(num_retries=NUM_RETRIES) |
|
|
|
|
if res.get('insertErrors', None): |
|
|
|
|
print 'Error inserting rows! Response: %s' % res |
|
|
|
|
print('Error inserting rows! Response: %s' % res) |
|
|
|
|
is_success = False |
|
|
|
|
except HttpError as http_error: |
|
|
|
|
print 'Error inserting rows to the table %s' % table_id |
|
|
|
|
print('Error inserting rows to the table %s' % table_id) |
|
|
|
|
is_success = False |
|
|
|
|
|
|
|
|
|
return is_success |
|
|
|
@ -176,8 +177,8 @@ def sync_query_job(big_query, project_id, query, timeout=5000): |
|
|
|
|
projectId=project_id, |
|
|
|
|
body=query_data).execute(num_retries=NUM_RETRIES) |
|
|
|
|
except HttpError as http_error: |
|
|
|
|
print 'Query execute job failed with error: %s' % http_error |
|
|
|
|
print http_error.content |
|
|
|
|
print('Query execute job failed with error: %s' % http_error) |
|
|
|
|
print(http_error.content) |
|
|
|
|
return query_job |
|
|
|
|
|
|
|
|
|
|
|
|
|
|