macでトレジャーデータを使ってみる


$ td --version
0.15.7
  • トレジャーデータにログイン
$ td account
> Enter your Treasure Data credentials. For Google SSO user, please see > https://docs.treasuredata.com/articles/command-line#google-sso-users
> Email: [email protected]
> Password (typing will be hidden): hogehoge
> Authenticated successfully.
  • データベースを確認
$ td db:list

+-----------------------------+-----------+
| Name                        | Count     |
+-----------------------------+-----------+
| sample_datasets             | 8812278   |
| test                        | 580262    |
| staging                     | 143968    |
| production                  | 636590027 |
| develop                     | 1482563   |
| information_schema          | 0         |
+-----------------------------+-----------+
  • テーブル確認
$ td db:show develop

+-------------------------------+------+--------+----------------------------------------------------------------------+
| Table                         | Type | Count  | Schema                                                               |
+-------------------------------+------+--------+----------------------------------------------------------------------+
| hogehoge                      | log  | 15     | id:long, aaaaa:long, bbbb:long, ccccccccccccc:long, dddddddddd:st... |
| fugafuga                      | log  | 13975  | id:long, aaaaa:long, bbbb:long, dddd:string, eeeeeeee:string, com... |
+-------------------------------+------+--------+----------------------------------------------------------------------+
  • クエリ発行
td query -d develop -w "select count(*) from hogehoge" 
  • オプション
-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
  • Presto利用で結果をCSVダウンロード
td query -d develop -T presto -w -o 'aaa.csv' -c "select count(*) from hogehoge"