new TDClient(apikey, options)
Treasure Data REST API Client
Parameters:
Name | Type | Description |
---|---|---|
apikey |
string | The API key available from user account. |
options |
object | Specify the endpoint of TreasureData api. options.host = 'api.treasuredata.com' options.protocol = 'http' |
- Version:
- 0.2.3
- License:
- Apache-2.0
- Source:
- See:
Requires:
- module:request
- module:querystring
- module:merge
Example
var TD = require('td');
var client = new TD('TREASURE_DATA_API_KEY');
var fnPrint = function(err, results) {
console.log(results);
};
client.listDatabase(function(err, results) {
for (var i = 0; i < results.databases.length; i++) {
client.listTables(results.databases[i].name, fnPrint);
}
});
Requires
- module:request
- module:querystring
- module:merge
Methods
(protected) _put()
_put: Protected method
(protected) _query()
_query: Protected method
(protected) _request()
_request: Protected method
bulkImportDeletePart(name, partName, callback)
Delete specified partition from given bulk import session
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The bulk import session name |
partName |
string | The partition name |
callback |
function | Callback function which receives error object and results object |
bulkImportUploadPart(name, partName, stream, callback)
Upload a partition file for the specified bulk import session
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The bulk import session name |
partName |
string | The partition name |
stream |
stream.Readable | Readable stream that reads partition file |
callback |
function | Callback function which receives error object and results object |
Example
var stream = fs.createReadStream('part_file.msgpack.gz');
client.bulkImportUploadPart('bulk_import_session', 'part1', stream, function(err, results) {
// Obtain bulk import uploading result
});
commitBulkImport(name, callback)
Confirm the bulk import session is finished successfully
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The bulk import session name |
callback |
Callback function which receives error object and results object |
createBulkImport(name, db, table, callback)
Create bulk import session
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The session name |
db |
string | Database name where data is imported |
table |
string | Table name where data is imported |
callback |
function | Callback function which receives error object and results object |
createDatabase(db, callback)
Create the given named database
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
callback |
function | Callback function which receives error object and results object |
createItemTable(db, table, callback)
Create item type table in the given database
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
table |
string | The name of table |
callback |
function | Callback function which receives error object and results object |
createLogTable(db, table, callback)
Create log type table in the given database
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
table |
string | The name of table |
callback |
function | Callback function which receives error object and results object |
createTable(db, table, type, callback)
Create table in given database
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
table |
string | The name of table |
type |
string | The type of table ('log' or 'item') |
callback |
function | Callback function which receives error object and results object |
deleteBulkImport(name, callback)
Delete bulk import session
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The session name |
callback |
function | Callback function which receives error object and results object |
deleteDatabase(db, callback)
Delete the given named database
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
callback |
function | Callback function which receives error object and results object |
hiveQuery(db, query, opts, callback)
Submit Hive type job
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
query |
string | The Hive query which run on given database |
opts |
object | Supported options are `result`, `priority` and `retry_limit` |
callback |
function | Callback function which receives error object and results object |
jobResult(job_id, format, callback)
Returns the result of a specific job.
Parameters:
Name | Type | Description |
---|---|---|
job_id |
string | The job id |
format |
string | Format to receive data back in, defaults to tsv |
callback |
function | Callback function which receives error object and results object |
kill(job_id, callback)
Kill the currently running job
Parameters:
Name | Type | Description |
---|---|---|
job_id |
string | the job id |
callback |
function | Callback function which receives error object and results object |
listBulkImportParts(callback)
Show the list of all partitions of specified bulk import session
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Callback function which receives error object and results object |
listBulkImports(callback)
Show the list of all bulk import sessions
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Callback function which receives error object and results object |
listDatabases(callback)
Return the list of all databases belongs to given account
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Callback function which receives error object and results object |
Example
// Results object
{name: 'db1', count: 1, created_at: 'XXX',
updated_at: 'YYY', organization: null,
permission: 'administrator'}
listJobs(from, to, status, callback)
Return the list of all jobs run by your account
Parameters:
Name | Type | Description |
---|---|---|
from |
string | The start of the range of list |
to |
string | The end of the range of list |
status |
string | The status of returned jobs |
callback |
function | Callback function which receives error object and results object |
listTables(db, callback)
Return the list of all tables belongs to given database
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
callback |
function | Callback function which receives error object and results object |
performBulkImport(name, callback)
Run the job for processing partition files inside Treasure Data service
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The bulk import session name |
callback |
Callback function which receives error object and results object |
prestoQuery(db, query, opts, callback)
Submit Presto type job
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
query |
string | The Presto query which run on given database |
opts |
object | Supported options are `result`, `priority` and `retry_limit` |
callback |
function | Callback function which receives error object and results object |
showBulkImport(name, callback)
Show the information about specified bulk import session
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The session name |
callback |
function | Callback function which receives error object and results object |
showJob(job_id, callback)
Returns the status and logs of a given job
Parameters:
Name | Type | Description |
---|---|---|
job_id |
string | The job id |
callback |
function | Callback function which receives error object and results object |
swapTable(db, table1, table2, callback)
Swap the content of two tables
Parameters:
Name | Type | Description |
---|---|---|
db |
string | The name of database |
table1 |
string | The first table |
table2 |
string | The second table |
callback |
function | Callback function which receives error object and results object |