Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery bq command - load only if table is empty or doesn't exist

I'm executing a load command with bq, e.g:

bq load ds.table gs://mybucket/data.csv dt:TIMESTAMP,f1:INTEGER

I would like to load the data only if the table is empty or doesn't exist.

Is it possible?

EDIT:

Basically I would like the WRITE_EMPTY API option via the bq command line tool:

https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load.writeDisposition

If the table already exists and contains data, a 'duplicate' error is returned in the job result.

like image 440
Eyal Levin Avatar asked Feb 17 '26 17:02

Eyal Levin


2 Answers

If you go check bq.py, that has the source code for the BigQuery CLI, you'll find out that the _Load() method doesn't implement an option for the WRITE_EMPTY API option. It's either the default WRITE_APPEND or the optional WRITE_TRUNCATE.

As you indicate, the API does support WRITE_EMPTY - if you want to see this as an option on the CLI, you can submit a feature request at https://code.google.com/p/google-bigquery/issues/list?q=label:Feature-Request

like image 142
Felipe Hoffa Avatar answered Feb 21 '26 14:02

Felipe Hoffa


You can use the BQ command-line tool.

Get Table Information

bq show <project_id>:<dataset_id>.<table_id>

List tables

 bq ls [project_id:][dataset_id]
like image 41
Pentium10 Avatar answered Feb 21 '26 14:02

Pentium10



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!