Я хочу добавить следующий файл , используя Python API, в таблицу BigQuery с нижеуказанной схемой:
[
{
"name": "batsman",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "batting_team",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "bowler",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "city",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "date",
"type": "DATE",
"mode": "NULLABLE"
},
{
"name": "delivery",
"type": "FLOAT",
"mode": "NULLABLE"
},
{
"name": "extras",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "extras_type",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "inning",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "match_code",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "non_striker",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "player_out",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "runs",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "team1",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "team2",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "toss_decision",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "toss_winner",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "total",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "venue",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "wicket_fielders",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "wicket_kind",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "win_margin",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "win_type",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "winner",
"type": "STRING",
"mode": "NULLABLE"
}
]
Код, который я использую для добавления вBigQuery выглядит следующим образом:
def insert_data_in_bq(bucketname, csv_filepath, table_id='ipl'):
"""Appends a csv to a BigQuery table."""
client = bigquery.Client()
dataset_id = 'cric'
dataset_ref = client.dataset(dataset_id)
job_config = bigquery.LoadJobConfig()
job_config.autodetect = True
job_config.skip_leading_rows = 1
job_config.source_format = bigquery.SourceFormat.CSV
# job_config.null_marker = 'NULL'
uri = 'gs://' + bucketname + '/' + csv_filepath
load_job = client.load_table_from_uri(uri, dataset_ref.table(table_id),
job_config=job_config) # API request
print('Starting job {}'.format(load_job.job_id))
load_job.result() # Waits for table load to complete.
print('Job finished.')
print('Loaded {} rows.'.format(load_job.output_rows))
Однако всякий раз, когда я загружаю файл, я получаю сообщение об ошибке:
BadRequest: 400 Invalid schema update. Field win_margin has changed type from INTEGER to STRING
Обычный файл будет выглядеть как this .
Что я должен сделать, чтобы я мог сохранить столбец win_margin
как INTEGER
и все же иметь возможность загрузить этот файл, содержащий все пустые строки для столбца?