def _table_creation_bq(_schema, db, data_set_name, table_name): if db.lower() == 'bigquery': bq_schema = [] # schema_dict = {} for i in _schema: schema_dict = {} t = i['type'] if t == 'object': schema_dict['name'] = i['name'] schema_dict['type'] = 'string' schema_dict['mode'] = 'nullable' elif t == 'int64': schema_dict['name'] = i['name'] schema_dict['type'] = 'integer' schema_dict['mode'] = 'nullable' elif t == 'float64': schema_dict['name'] = i['name'] schema_dict['type'] = 'float' schema_dict['mode'] = 'nullable' elif t == 'datetime64[ns]': schema_dict['name'] = i['name'] schema_dict['type'] = 'TIMESTAMP' schema_dict['mode'] = 'nullable' bq_schema.append(schema_dict) print 'Table creation started!' print table_name try: print data_set_name result = bq.create_Table(data_set_name,table_name,bq_schema) if result: print "Table creation succcessful!" else: print "Error occurred while creating table! If table already exists data might insert to the existing table!" except Exception, err: print "Error occurred while creating table!" print err raise
print err result = comm.format_response(False,err,"failed read csv file",exception=sys.exc_info()) return result print "Field type recognition successful" if db.lower() == 'bigquery': try: table_existance = bq.check_table(dataset_name,table_name) if table_existance : if parms.folder_type.lower() == 'singlefile': bq.delete_table(dataset_name,table_name) print "Existing Table deleted" try: print dataset_name result = bq.create_Table(dataset_name, table_name, schema) if result: print "Table creation succcessful!" else: print "Error occurred while creating table! If table already exists data might insert to the existing table!" except Exception, err: print "Error occurred while creating table!" print err raise else: try: print dataset_name result = bq.create_Table(dataset_name,table_name,schema) if result: print "Table creation succcessful!"