7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

bq load コマンドの基本

Last updated at Posted at 2016-11-22

フォーマット

次の形式でコマンドを叩く。三つとも必須。

bq load [BQのテーブル名] [リソースファイルのパス] [スキーマ指定]

たとえばこういうファイルがある場合。

example.txt
Alice,20
Bob,21
Carol,22

次のコマンドでBQにテーブルを作れる。

bq load bq_dataset.table example.txt name:string,age:integer

追記 / 置換

ちなみにデフォルトの動作は「追記」なので、二回実行すると同じデータが作られる。

image

置換する場合は --replace を指定すること。

bq load --replace bq_dataset.table example.txt name:string,age:integer
bq load bq_dataset.table example.txt name:string,age:integer

フォーマットの指定

区切り文字がカンマ以外の場合は、--field_delimiter を指定する必要がある。

例: スペース区切りの場合

example.txt
Alice 20
Bob 21
Carol 22
bq load --field_delimiter=' ' bq_dataset.table example.txt name:string,age:integer

「リソースファイルのパス」は GCS(GoogleCloudStorage) 上のパスでも良い。(こちらの方が高速)
ただし「スキーマファイルのパス」はローカルのものでなければいけない。

bq load bq_dataset.table gs://bucket/log.gz /tmp/schema.json

--nosync オプション

非同期で実行する。

環境

  • Google Cloud SDK 134.0.0
  • bq 2.0.24

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?