The official unofficial port of the Tableau Extract API for Node.js. Create Hyper
Extracts for use in Tableau Desktop, Tableau Server, or Tableau Online using JavaScript!
Installation
Warning: Under active development. Currently only known to work on OSX and
Ubuntu using LTS versions of node (v6, v8, v10). Check the issue queue for updates
or to contribute improvements!
- Install the C/C++ Tableau SDK
for your platform,
- You may need to install node-gyp (
npm install node-gyp -g
)
- If you're on OS X, be sure XCode and command line tools are installed. You
may need to run
xcode-select --install
- Pull the SDK from npm.
npm install tableau-sdk --save
,
Usage
Check the examples folder
for sample usage, or see some examples below.
For simplicity, this API borrows the TableInfo
and ColumnInfo
data structures from the Tableau Web Data Connector API. In addition to the data
types supported by the WDC API. Note, while the underlying C++ Extract API uses
Spatial
to indicate spatial data types, the WDC API uses geometry
. We follow
that convention here too.
Create an extract and add data
let ExtractApi = require('tableau-sdk'),
tableDefinition,
extract;
tableDefinition = {
id: 'Extract',
defaultAlias: 'Product Prices',
columns: [
{id: 'Product', dataType: 'string'},
{id: 'Price', dataType: 'float'}
]
};
extract = new ExtractApi('/path/to/your.hyper', tableDefinition);
extract.insert({
Price: 3.99,
Product: '12 oz Latte'
});
extract.close();
Open an existing extract and add data
let ExtractApi = require('tableau-sdk'),
extract;
extract = new ExtractApi('/path/to/your.hyper');
extract.insert([
'12 oz Americano',
2.95
]);
extract.close();
Create a multi-table extract and add data
let ExtractApi = require('tableau-sdk'),
tables,
extract;
tables = {
products: {
id: 'Products',
defaultAlias: 'Products',
columns: [
{id: 'ProductID', dataType: 'int'},
{id: 'Product', dataType: 'string'},
{id: 'Price', dataType: 'float'}
]
},
orders: {
id: 'Orders',
defaultAlias: 'Product Orders',
columns: [
{id: 'OrderID', dataType: 'int'},
{id: 'ProductID', dataType: 'int'},
{id: 'Customer', dataType: 'string'}
]
}
};
extract = new ExtractApi('/path/to/your.hyper');
extract.addTable('Products', tables.products);
extract.addTable('Orders', tables.orders);
extract.insert('Products', [{
ProductID: 1,
Product: '12 oz Latte',
Price: 3.99
}, {
ProductID: 2,
Product: '16 oz Latte',
Price: 4.99
}]);
extract.insert(tables.orders.id, {
OrderID: 1,
ProductID: 2,
Customer: 'Jane'
});
extract.close();
Date handling
If your extract includes a date or datetime, you can pass the value in one of
three ways:
- As a string that is in an ISO format recognized by moment.js.
This is the simplest way to insert dates into to your extract
- As a string exactly conforming to either
YYYY-MM-DD
or YYYY-MM-DD HH:MM:SS
.
This is the most performant way to insert dates into your extract, and is
recommended for very large datasets wherever possible.
- As an object instance of
moment
. This may be the most performant way to
insert dates into your extract in situations where you are already using the
moment.js
library to manipulate dates prior to insertion.
Advanced usage (native APIs)
This API provides a thin wrapper around the native C/C++ Tableau SDK that
handles most use-cases. If you have more advanced use-cases (for example, if you
need certain columns in your extract to be collated a certain way), it's
possible for you to more directly interface with the native C/C++ API.
In those cases, the following static methods are available for you on the main
SDK object:
var tableau = require('tableau-sdk');
tableau.dataExtract;
tableau.tableDefinition;
tableau.tableRow;
tableau.enums;
See advanced examples
for more details. You may also wish to refer to the C++ API reference docs.