Service for interfacing with TreasureData for the Okanjo App ecosystem.
Add to your project like so:
npm install okanjo-app-td
Note: requires the okanjo-app
module.
Service for working with TreasureData queries.
const TreasureDataService = require('okanjo-app-td');
service.app
– (read-only) The OkanjoApp instance provided when constructedservice.config
– (read-only) The service configuration provided when constructedservice.tdClient
– (read-only) The underlying TreasureData Node.js Client
Creates a new service instance.
app
– The OkanjoApp instance to bind toconfig
– (Required) The service configuration object.config.apiKey
– (Required) The TD API key to pass to the underlying TD client.config.jobStatusPollInterval
– (Optional) Job status polling interval (in ms).
Executes a new query.
db
- The name of the database to query againstquery
– The SQL query bodyoptions
- (optional) Query options. Defaults to{}
options.hive
– (optional) Whether to run the query using Hive (true
) or Presto (false
). Defaults tofalse
.options.*
- Passed to the underlyingprestoQuery
orhiveQuery
TD client call.
Returns Promise<array>
, where each row is mapped to an object using the output column names as keys.
Executes a new query.
name
- The name stored query to runoptions
- (optional) Query options. Defaults to{}
options.scheduledTime
– (optional) The scheduled time the job will execute using. Defaults toDate.now
.
Returns Promise<array>
, where each row is mapped to an object using the output column names as keys.
Starts a new presto query job.
db
- The name of the database to query againstquery
– The SQL query bodyoptions
- (optional) Query options. Defaults to{}
Returns Promise<response>
, where response is the TD JSON response.
Starts a new hive query job.
db
- The name of the database to query againstquery
– The SQL query bodyoptions
- (optional) Query options. Defaults to{}
Returns Promise<response>
, where response is the TD JSON response.
Gets the status of a job.
jobId
– Query job id
Returns Promise<response>
, where response is the TD JSON response.
Resolves once the job has completed.
jobId
– Query job id
Returns Promise<response>
, where response is the TD JSON response.
- Resolves when the job status is
success
. - Rejects if the job status is
error
orkilled
.
Gets the output schema of a job.
jobId
– Query job id
Returns Promise<schema>
, where schema is the parsed column schema.
Gets the output row data of a job.
jobId
– Query job id
Returns Promise<rows>
Returns a mapped array of row objects whose keys are the query column names.
schema
- Job output schemarows
- Job output rows
Returns an Array
of mapped row objects.
This class does not emit events.
Our goal is quality-driven development. Please ensure that 100% of the code is covered with testing.
Before contributing pull requests, please ensure that changes are covered with unit tests, and that all are passing.
To run unit tests and code coverage:
npm run report
This will perform:
- Unit tests
- Code coverage report
- Code linting
Sometimes, that's overkill to quickly test a quick change. To run just the unit tests:
npm test
or if you have mocha installed globally, you may run mocha test
instead.