[A-00099]ShellからBigQueryにコマンドを実行する
シェルスクリプトからBQに対してコマンドを実行する方法を記載しておく。
Google公式ドキュメントはこちら
https://cloud.google.com/bigquery/docs/managing-datasets?hl=ja
・データセットを作成する
bq --location=<location_name> mk --dataset --project_id=<project_id> <dataset_name>
MacBook-Pro:~$ bq --location=asia-northeast1 mk --dataset --project_id=xxxxx TEST
/Users/anonymous/Documents/Google/google-cloud-sdk/platform/bq/bq.py:18: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
import pipes
Dataset 'xxxxx:TEST' successfully created.

・データセットを削除する
bq rm -r -f -d <project_id>:<dataset_name>
MacBook-Pro:~$ bq rm -r -f -d xxxxx:TEST
/Users/anonymous/Documents/Google/google-cloud-sdk/platform/bq/bq.py:18: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
import pipes

・テーブルを作成する
bq mk --table <project_id>:<dataset_name>.<table_name> <schema>
bq mk --table xxxxx:TEST.T_EMP id:INTEGER,name:STRING,age:INTEGER,address:STRING
MacBook-Pro:~$ bq mk --table xxxxx:TEST.T_EMP id:INTEGER,name:STRING,age:INTEGER,address:STRING
/Users/anonymous/Documents/Google/google-cloud-sdk/platform/bq/bq.py:18: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
import pipes
Table 'xxxxx:TEST.T_EMP' successfully created.

・テーブルを削除する
bq rm -f -t <project_id>:<dataset_name>.<table_name>
MacBook-Pro:~$ bq rm -f -t soy-braid-298113:TEST.T_EMP
/Users/anonymous/Documents/Google/google-cloud-sdk/platform/bq/bq.py:18: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
import pipes

コメントを残す