# TD Toolbelt ジョブとクエリコマンドリファレンス [TD Toolbelt リファレンス](https://api-docs.treasuredata.com/en/tools/cli/api/#td-toolbelt-reference) および [追加の TD Toolbelt ドキュメント](https://api-docs.treasuredata.com/en/tools/cli/quickstart/#td-toolbelt-quickstart) は [Treasure Data Developer Portal](https://api-docs.treasuredata.com/) で確認できます。 * [TD Query](#td-query-sql) * [使用方法](#usage) * [オプション](#options) * [例](#examples) * [TD Jobs](#td-jobs) * [使用方法](#usage-1) * [オプション](#options-1) * [TD Job ](#td-job-job_id) 通常、TD Toolbelt を使用してクエリを実行する場合、ジョブが完了するまで待機します。 -w オプションを使用 *せずに* クエリを発行すると、ジョブを送信した直後にコマンドが終了します。 * [TD Query](#td-query-sql) * [使用方法](#usage) * [オプション](#options) * [例](#examples) * [TD Jobs](#td-jobs) * [使用方法](#usage-1) * [オプション](#options-1) * [TD Job ](#td-job-job_id) # td query [sql] ## 使用方法 ```bash $ td query [sql] ``` ## オプション ```bash options: -d, --database DB_NAME use the database (required) -w, --wait[=SECONDS] wait for finishing the job (for seconds) -G, --vertical use vertical table to show results -o, --output PATH write result to the file -f, --format FORMAT format of the result to write to the file (tsv, csv, json, msgpack, and msgpack.gz) -r, --result RESULT_URL write result to the URL (see also result:create subcommand) It is suggested for this option to be used with the -x / --exclude option to suppress printing of the query result to stdout or -o / --output to dump the query result into a file. -u, --user NAME set user name for the result URL -p, --password ask password for the result URL -P, --priority PRIORITY set priority -R, --retry COUNT automatic retrying count -q, --query PATH use file instead of inline query -T, --type TYPE set query type (hive, presto) --sampling DENOMINATOR OBSOLETE - enable random sampling to reduce records 1/DENOMINATOR -l, --limit ROWS limit the number of result rows shown when not outputting to file -c, --column-header output of the columns' header when the schema is available for the table (only applies to json, tsv and csv formats) -x, --exclude do not automatically retrieve the job result -O, --pool-name NAME specify resource pool by name --domain-key DOMAIN_KEY optional user-provided unique ID. You can include this ID with your `create` request to ensure idempotence --engine-version ENGINE_VERSION EXPERIMENTAL: specify query engine version by name ``` ## 例 例えば、-w オプションを使用します: `$ td query -w -d testdb "SELECT COUNT(1) FROM www_access"` `Job 702 is started.` -w オプションを使用 *せずに* クエリを発行すると、ジョブを送信した直後にコマンドが終了します。例: `$ td query -d testdb "SELECT COUNT(1) FROM www_access"` `Job 704 is started.` `Use 'td job 704' to show the status.` ジョブ結果を STDOUT ではなく、ローカルディスクに CSV 形式で出力できます。 `$ td query -o test.csv --format csv -w -d testdb 'SELECT COUNT(1) FROM www_access'` `Status : success` `Result : written to test.csv in csv format` # TD Jobs td jobs コマンドは、送信されたジョブを一覧表示します。デフォルトでは、最新の 20 件のジョブが表示されます。 ## 使用方法 ```bash $ td job:list [max] ``` ## オプション ```bash options: -p, --page PAGE skip N pages -s, --skip N skip N jobs -R, --running show only running jobs -S, --success show only succeeded jobs -E, --error show only failed jobs --slow [SECONDS] show slow queries (default threshold: 3600 seconds) -f, --format FORMAT format of the result rendering (tsv, csv, json or table. default is table) ``` | **コマンド例** | **表示内容** | | --- | --- | | $ td jobs -p 0 | 最新の 20 件のジョブ | | $ td jobs -p 1 | ジョブ 21-40 | | $ td jobs -p 2 | ジョブ 41-60 | # td job このコマンドは、特定のジョブの詳細情報を表示します。 ```bash $ td job 10349872 ``` 例: ![](/assets/image-20190829-231407.6d1b7e391cfa346a8c394174935014e92f2251d179ad23eca546ed3a37fff8a4.60bcc915.png)