Contract schema
Field-level reference for the Gaur contract definition JSON.
A contract is a JSON document. This page is the field-level reference. For the conceptual walkthrough, see Anatomy of a contract; for the raw, canonical JSON Schema, see JSON schema.
Identifiers for contract names, dimension names, and measure names match the
pattern ^[a-z_][a-z0-9_]*$: lowercase letters, digits, and underscores, not
starting with a digit.
Top level
Prop
Type
Source
sources is an ordered array. The first source is the anchor and declares
only source_type, name, and alias. Every later source is a join and
also declares join_type, cardinality, and on.
Every joined source must point at a table or
model that has a
primary key declared, and the join's
on has to reference that key. The primary key lives on the table or model,
not in the contract schema, so it isn't a field listed below.
Prop
Type
"sources": [
{ "source_type": "table", "name": "orders", "alias": "o" },
{
"source_type": "table", "name": "regions", "alias": "r",
"join_type": "left", "cardinality": "many_to_one", "on": "o.region_id = r.id"
}
]Dimension
Each entry in dimensions is keyed by the dimension name.
Prop
Type
Measure
Each entry in measures is keyed by the measure name and is one of three
shapes, set by behavior. See Measures.
Standard measure
Prop
Type
Rolling measure
Prop
Type
Derived measure
Prop
Type
Rls
The optional rls object scopes rows per caller. See
Row-level security.
Prop
Type
Full example
{
"name": "store_performance",
"description": "Per-store performance: revenue, units sold, average ticket value, sliced by store and date.",
"sources": [
{ "source_type": "model", "name": "orders_clean", "alias": "o" },
{ "source_type": "model", "name": "stores_enriched", "alias": "s",
"join_type": "left", "cardinality": "many_to_one",
"on": "o.store_id = s.store_id" }
],
"dimensions": {
"store_id": { "sql": "s.store_id", "type": "string" },
"store_name": { "sql": "s.store_name", "type": "string" },
"ordered_at": {
"sql": "o.ordered_at", "type": "timestamp",
"semantic_type": "time", "time_grains": ["day", "week", "month", "quarter", "year"]
}
},
"measures": {
"revenue_usd": { "sql": "sum(o.subtotal_usd)", "type": "number", "additivity": "additive" },
"order_count": { "sql": "count(*)", "type": "number", "additivity": "additive" },
"avg_ticket_value": { "behavior": "derived", "type": "number",
"numerator": "revenue_usd", "denominator": "order_count" }
},
"filters": null,
"rls": {
"sql": "s.store_id = {{ store_id }}",
"parameters": { "store_id": "request.store_id" }
}
}