bq commandのscheduled query操作メモ


ただのメモです。

scheduled query一覧表示

$ bq ls --transfer_config --transfer_location=us
                                           name                                                              displayName                      dataSourceId       state
 ----------------------------------------------------------------------------------------- ------------------------------------------------ ----------------- -----------
  projects/000000000000/locations/us/transferConfigs/00000000-0000-0000-0000-000000000000   my_scheduled_query                               scheduled_query   SUCCEEDED

scheduled queryの設定表示

$ bq show --format=prettyjson --transfer_config "projects/000000000000/locations/us/transferConfigs/00000000-0000-0000-0000-000000000000"
{
  "dataSourceId": "scheduled_query",
  "datasetRegion": "us",
  "destinationDatasetId": "samples",
  "displayName": "my_scheduled_query",
  "emailPreferences": {
    "enableFailureEmail": true
  },
  "name": "projects/000000000000/locations/us/transferConfigs/00000000-0000-0000-0000-000000000000",
  "params": {
    "destination_table_name_template": "sample2",
    "query": "SELECT * FROM samples.sample LIMIT 1",
    "write_disposition": "WRITE_APPEND"
  },
  "scheduleOptions": {
    "disableAutoScheduling": true
  },
  "state": "FAILED",
  "updateTime": "2020-01-01T00:00:00.000000Z",
  "userId": "xxxxxxxxxxxxxxxxxxx"
}

OnDemandQueryを実行する

$ bq mk \
  --transfer_run \
  --run_time="2020-01-01T00:00:00+09:00" \
  projects/000000000000/locations/us/transferConfigs/00000000-0000-0000-0000-000000000000

scheduled queryを更新する

$ cat << __JSON__ > /tmp/param.json
{
  "query": "SELECT * FROM samples.sample LIMIT 2",
  "destination_table_name_template": "sample2",
  "write_disposition": "WRITE_APPEND"
}
__JSON__

$ bq update \
  --transfer_config \
  --params="$(cat /tmp/param.json)" \
  projects/000000000000/locations/us/transferConfigs/00000000-0000-0000-0000-000000000000