|
|
|
@ -13,6 +13,8 @@ |
|
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
|
# limitations under the License. |
|
|
|
|
|
|
|
|
|
from __future__ import print_function |
|
|
|
|
|
|
|
|
|
import argparse |
|
|
|
|
import json |
|
|
|
|
import uuid |
|
|
|
@ -50,11 +52,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 |
|
|
|
|
|
|
|
|
@ -122,13 +124,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 |
|
|
|
|
|
|
|
|
@ -154,9 +156,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 |
|
|
|
|
|
|
|
|
@ -172,10 +174,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 |
|
|
|
@ -189,8 +191,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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|