Ruby SDK Data Import

This article describes how to import the data from your Ruby applications, using Treasure Data’s Ruby SDK,

Table of Contents


  • Basic knowledge of Ruby, Gems, and Bundler.
  • Basic knowledge of Treasure Data.
  • Ruby 1.9 or higher (for local testing).

Step 1: Install ‘td’ Gem

First, please add the td (‘T’reasure ‘D’ata) gem to your Gemfile.

gem 'td', "~> 0.11.1"

Next, install the gem locally via bundler.

$ bundle install

Step 2: Modify Your App

The ‘td’ gem comes with a built-in library for recording in-app events. Insert code as shown below to record events from your app. Further details regarding the event logger API can be found here.

YOUR_API_KEY should be your actual apikey string. You can retrieve your api key from HERE.
# Initialization'production',

# Example1: login event'login', {:uid=>123})

# Example2: follow event'follow', {:uid=>123, :from=>'TreasureData', :to=>'kzk_mover'})

# Example3: pay event'pay',
              {:uid=>123, :item_name=>'Stone of Jordan',
               :category=>'ring', :price=>100, :count=>1})

Your event-logging code should be placed near its corresponding event-generating code.

When using the td gem, the posted records are buffered in the memory locally at first, and the data is uploaded every 5 minutes. Because a dedicated thread uploads the data into the cloud, it doesn’t affect your application’s response time.

The local buffer also has a size limit. If the local data exceeds this limit, the records will be uploaded immediately.

Step 3: Confirming Data Import

The data gets uploaded in every 5 minutes. You can confirm the data import either from Web Console or CLI.

From Web Console

To confirm that your data has been uploaded successfully, check your dataset from the web browser HERE.

From CLI

Or, please issue the td tables command if you have a CLI client.

$ td tables
| Database   | Table      | Type | Count     |
| production | login      | log  | 1         |
| production | follow     | log  | 1         |
| production | pay        | log  | 1         |

Next Steps

We offer a schema mechanism that is more flexible than that of traditional RDBMSs. For queries, we leverage the Hive Query Language.

Last modified: May 19 2016 02:28:09 UTC

If this article is incorrect or outdated, or omits critical information, please let us know. For all other issues, please see our support channels.