Creating a Metric from a Data Warehouse or Cube Connection
Map a data warehouse table/field or a Cube view/field into a metric spec.
-
GET /direct_connections— find a connection with adataBaseTypeother thandbt(e.g.postgresql,snowflake,bigquery, orcube). -
GET /direct_connections/:connectionId/tables— list the tables/views (or, for a Cube connection, the cubes/views) the connection can query. -
GET /direct_connections/:connectionId/tables/:tableName/fields— list that table's fields. A field'stypeismetric(an aggregatable value — the candidate forfieldId) ordimension(a candidate fortimeRefId, if itsdataTypeis a date/time, or otherwise for an entry indimensions[]). -
POST /metrics— map the connection id, table, and fields into the spec. The mapping differs by connector:sourceTypefieldId/timeRefId/dimensions[].fieldIdproperties.tableNamePlain SQL warehouse (Postgres, Snowflake, BigQuery, ...) SQLthe field's bare name, unqualifiedrequired — the table it came from Cube CUBEthe field's nameas returned — Cube already qualifies it<view>.<field>not used
A dimension's dataType must be one of the metric schema's own enum values (STRING, DATE, DOUBLE, BOOLEAN) — translate the connector's own type name onto it, e.g. int/double/decimal/numeric → DOUBLE, date/datetime/timestamp → DATE, boolean/bool → BOOLEAN, anything else → STRING.
Each dimension field you want the metric filterable and groupable by gets its own entry in dimensions[]; the examples below take two.
SQL warehouse example — fields amount (metric, double), created_at (dimension, datetime), status (dimension, string) and region (dimension, string) on table orders:
{
"name": "Order Amount",
"description": "Order total from the orders table",
"sourceType": "SQL",
"sourceId": "13451dc615244a9cb6c99203a3abbea5",
"fieldId": "amount",
"timeRefId": "created_at",
"properties": { "tableName": "orders" },
"dimensions": [
{ "name": "Status", "fieldId": "status", "dataType": "STRING" },
{ "name": "Region", "fieldId": "region", "dataType": "STRING" }
]
}Cube example — fields already qualified with their view, so no tableName:
{
"name": "Order Amount",
"description": "Order total from the Orders view",
"sourceType": "CUBE",
"sourceId": "13451dc615244a9cb6c99203a3abbea5",
"fieldId": "Orders.amount",
"timeRefId": "Orders.createdAt",
"dimensions": [
{ "name": "Status", "fieldId": "Orders.status", "dataType": "STRING" },
{ "name": "Region", "fieldId": "Orders.region", "dataType": "STRING" }
]
}Updated 6 days ago