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.

  1. GET /direct_connections — find a connection with a dataBaseType other than dbt (e.g. postgresql, snowflake, bigquery, or cube).

  2. GET /direct_connections/:connectionId/tables — list the tables/views (or, for a Cube connection, the cubes/views) the connection can query.

  3. GET /direct_connections/:connectionId/tables/:tableName/fields — list that table's fields. A field's type is metric (an aggregatable value — the candidate for fieldId) or dimension (a candidate for timeRefId, if its dataType is a date/time, or otherwise for an entry in dimensions[]).

  4. POST /metrics — map the connection id, table, and fields into the spec. The mapping differs by connector:

    sourceTypefieldId / timeRefId / dimensions[].fieldIdproperties.tableName
    Plain SQL warehouse (Postgres, Snowflake, BigQuery, ...)SQLthe field's bare name, unqualifiedrequired — the table it came from
    CubeCUBEthe field's name as 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/numericDOUBLE, date/datetime/timestampDATE, boolean/boolBOOLEAN, 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" }
  ]
}

Did this page help you?