MATIH Platform is in active MVP development. Documentation reflects current implementation status.
10. Data Catalog & Governance
Semantic Layer
Metric Queries

Metric Queries

Metric Queries allow users to request data from semantic models by specifying metrics, dimensions, filters, and time ranges. The Semantic Layer compiles these high-level requests into optimized SQL and executes them against the Query Engine. This abstraction eliminates the need for users to write SQL directly while ensuring queries are consistent with the defined business logic.


Query Structure

A metric query specifies what to compute and how to slice the results.

FieldTypeRequiredDescription
modelIdUUIDYesSemantic model to query
metricsListNoMetric names to compute
dimensionsListNoDimensions to group by
filtersListNoFilter conditions
orderByListNoSort order
timeDimensionStringNoTime dimension for temporal queries
timeGrainStringNoTemporal granularity (DAY, WEEK, MONTH, QUARTER, YEAR)
timeRangeStartInstantNoStart of time range
timeRangeEndInstantNoEnd of time range
relativeTimeRangeStringNoRelative time expression (e.g., "last 30 days")
limitIntegerNoMaximum rows to return
offsetIntegerNoRow offset for pagination
useCacheBooleanNoWhether to use cached results
timeoutSecondsIntegerNoQuery timeout

Example Query

{
  "modelId": "550e8400-e29b-41d4-a716-446655440000",
  "metrics": ["total_revenue", "order_count"],
  "dimensions": ["region", "order_date"],
  "filters": [
    {
      "field": "region",
      "operator": "IN",
      "values": ["US", "EU"]
    },
    {
      "field": "order_total",
      "operator": ">=",
      "value": 100
    }
  ],
  "orderBy": [
    {
      "field": "total_revenue",
      "descending": true
    }
  ],
  "timeDimension": "order_date",
  "timeGrain": "MONTH",
  "timeRangeStart": "2026-01-01T00:00:00Z",
  "timeRangeEnd": "2026-12-31T23:59:59Z",
  "limit": 100
}

Filter Operators

OperatorDescriptionExample
=Equalsregion = 'US'
!=Not equalsstatus != 'cancelled'
>Greater thanamount > 100
>=Greater than or equalamount >= 100
<Less thanamount < 1000
<=Less than or equalamount <= 1000
INIn listregion IN ('US', 'EU')
NOT_INNot in liststatus NOT_IN ('cancelled', 'refunded')
LIKEPattern matchname LIKE '%smith%'
IS_NULLIs nullemail IS NULL
IS_NOT_NULLIs not nullemail IS NOT NULL
BETWEENRangeamount BETWEEN 100 AND 1000

Query Compilation

The compilation process transforms a semantic query into executable SQL.

StepDescription
1Resolve model and verify metrics/dimensions exist
2Build SELECT clause from metrics (with aggregation) and dimensions
3Build FROM clause using the model table reference
4Traverse relationships and add JOINs for cross-model references
5Build WHERE clause from filters
6Build GROUP BY clause from dimensions
7Build ORDER BY clause
8Apply LIMIT and OFFSET
9Pass compiled SQL through the query optimizer

Query Result Structure

{
  "data": [
    {
      "region": "US",
      "order_date": "2026-01",
      "total_revenue": 1250000.00,
      "order_count": 4520
    }
  ],
  "columns": [
    {
      "name": "region",
      "type": "VARCHAR",
      "displayName": "Region",
      "isDimension": true,
      "isMetric": false,
      "nullable": false
    },
    {
      "name": "total_revenue",
      "type": "DECIMAL",
      "displayName": "Total Revenue",
      "isDimension": false,
      "isMetric": true,
      "nullable": true
    }
  ],
  "totalRows": 24,
  "executionTimeMs": 342,
  "fromCache": false,
  "sql": "SELECT ... FROM ... WHERE ... GROUP BY ..."
}

Time Grain Options

GrainDescription
DAYDaily aggregation
WEEKWeekly aggregation
MONTHMonthly aggregation
QUARTERQuarterly aggregation
YEARYearly aggregation

Saved Queries

Users can save frequently used metric queries for reuse.

FieldDescription
nameQuery name (required, max 256 characters)
descriptionDescription of the query
isPublicWhether other tenant users can see the saved query
compiledSqlThe compiled SQL stored for reference
executionCountNumber of times the query has been executed
lastExecutedAtTimestamp of the last execution

Caching

Metric queries support result caching. When useCache is set to true, the Semantic Layer checks for cached results before compiling and executing the query. Cache keys are derived from the query parameters and tenant context.