The Treasure Data CLI allows you to create databases and tables, issue queries, view existing job results, and import/export data.
Table of Contents
Install the Treasure Data Toolbelt to set up your local workstation with
td, the Treasure Data command-line client.
|If you've followed the Quickstart Guide, you've already installed this.|
If you are familiar with Ruby, you can install
td from the command line using
$ gem install td
Alternative installation options, including a Mac OSX installer and a Windows installer, can be found on the Treasure Data Toolbelt page.
Step 1: Authorize
Once you have installed the toolbelt, you will have access to the
td command from your command line. Authorize your account with the
td account command. Please use the user name and password you used when signing up when prompted.
$ td account -f Enter your Treasure Data credentials. Email: email@example.com Password (typing will be hidden): Authenticated successfully.
Step 2: Query the Sample Dataset
Let’s issue a SQL query. Out of the box, we have a table called www_access in the dabase called sample_db. The following query calculates the distribution of HTTP status codes.
$ td query -w -d sample_db \ "SELECT code, COUNT(1) AS cnt FROM www_access GROUP BY code" queued... started at 2012-04-10T23:44:41Z 2012-04-10 23:43:12,692 Stage-1 map = 0%, reduce = 0% 2012-04-10 23:43:18,766 Stage-1 map = 100%, reduce = 0% 2012-04-10 23:43:29,925 Stage-1 map = 100%, reduce = 33% 2012-04-10 23:43:32,973 Stage-1 map = 100%, reduce = 100% Status : success Result : +------+------+ | code | cnt | +------+------+ | 404 | 17 | | 500 | 2 | | 200 | 4981 | +------+------+
The command above will take about 15-45 seconds, owing mainly to the overhead in setting up jobs within the cloud-based MapReduce engine.
You’re now ready to import your real data to the cloud! The following tutorials will explain how to import your data (e.g. Application Logs, Middleware Logs) from various sources. For a deeper understanding of the platform, please refer to the architecture overview article.
Languages and Frameworks
|Ruby or Rails||Java||Perl|
td help:all shows the commands available in Treasure Data:
$ td help:all db:list # Show list of tables in a database db:show <db> # Describe a information of a database db:create <db> # Create a database db:delete <db> # Delete a database ....
If you want more information about individual commands, you can run
td help <command>:<subcommand>, e.g.,
$ td help table:list usage: $ td table:list [db] example: $ td table:list $ td table:list example_db $ td tables description: Show list of tables options: -n, --num_threads VAL number of threads to get list in parallel --show-bytes show estimated table size in bytes