I'm creating a flow to insert rows in a BigQuery table from a list of dictionaries with the following format:
[
{'column1': 'value11', 'column2': 'value21', 'column3': [{'subfield1':'value131'}]},
{'column1': 'value12', 'column2': 'value22', 'column3': [{'subfield1':'value231'}]},
{'column1': 'value12', 'column2': 'value22', 'column3': [{'subfield1':'value331'}]}
]
I'm testing yet and wish to write truncate the table, but I don't know how to set the job_config for an insert_rows method. I set up a LoadJobConfig object as follows, but the insert_rows method doesn't accept job_config as a parameter.
job_config = bigquery.LoadJobConfig(
schema=schema,
write_disposition=bigquery.WriteDisposition.WRITE_TRUNCATE
)
I'm not loading the from a DataFrame or a file because my table has nested fields and I didn't find out how to load nested data in those formats.
Can anyone help me?
You can't pass
JobConfigwithWRITE_TRUNCATEmode. You have to execute a separated query totruncatethe table, then append all your dicts toBigQuerywithinsert_rows_json:The
insert_rows_jsonuses the following insertAll api.