Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions core-spec/expression_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ will be able to be multi-part and the parts will be separated by the '.' charact

What an identifier refers to depends on where the expression appears:

* In a **field expression**, identifiers refer to columns of the dataset's `source`. A field expression cannot refer to other fields.
* In a **dataset-scoped metric expression**, unqualified identifiers refer to fields declared in that dataset, even when a source column has the same name. Identifiers qualified with `source`, as in `source.column`, refer to columns of the dataset's `source`. The `source` qualifier is case insensitive. If the dataset declares a field named `source`, the name refers to that field, and the dataset's metrics cannot refer to source columns.
* In a **field expression**, identifiers refer to columns of the dataset's `source`. A field expression cannot refer to other fields or to a measure column of the `source`.
* In a **dataset-scoped metric expression**, unqualified identifiers refer to fields declared in that dataset, even when a source column has the same name. Identifiers qualified with `source`, as in `source.column`, refer to columns of the dataset's `source`. The `source` qualifier is case insensitive. If the dataset declares a field named `source`, the name refers to that field, and the dataset's metrics cannot refer to source columns. Inside `AGG`, an identifier written `source.measure` refers to a measure column of the dataset's `source`; this is the only way to refer to a source measure.
* In a **model-scoped metric expression**, identifiers must be qualified. An identifier written `dataset.field` refers to a field declared in that dataset, not to a source column. Inside `AGG`, an identifier written `dataset.metric` refers to a dataset-scoped metric of that dataset; this `AGG(dataset.metric)` form is the only way to reference a metric.

See [Name Resolution](spec.md#name-resolution) in the core specification.
Expand Down Expand Up @@ -152,7 +152,7 @@ Ossie expressions support the following SQL constructs within any expression:
| `UNION` / `INTERSECT` / `EXCEPT` | Not applicable to expressions |
| DDL statements | Out of scope |
| DML statements | Out of scope |
| `AGG(...)` outside a model-scoped metric | Reserved for a future version. See [Measure Evaluation: `AGG`](#measure-evaluation-agg). |
| `AGG(...)` outside a metric | Reserved for a future version. Metrics may call `AGG` only in the forms that [Measure Evaluation: `AGG`](#measure-evaluation-agg) lists. |

### Operator Precedence

Expand Down Expand Up @@ -284,7 +284,12 @@ A non-matching row contributes `NULL`, which these functions ignore. An `ELSE 0`

Ossie SQL reserves the function name `AGG` for evaluating a measure: a column that holds an aggregate calculation instead of a value for each row. The [Relational Query Interface](relational_semantics.md) defines measures (Section 4) and `AGG` (Section 6), including its valid arguments. In `OSSIE_SQL_2026` expressions, an implementation MUST NOT give `AGG` any other meaning. Expressions in other dialects are not affected. Because function names should be case insensitive, the reservation covers every capitalization, such as `agg` and `Agg`.

A model-scoped metric may use `AGG` to evaluate a dataset-scoped metric, as in `AGG(orders.total_revenue)`. The argument is a single `dataset.metric` reference, and the call takes no `FILTER (WHERE ...)` clause (see [Metric Scoping](spec.md#metric-scoping)). `OSSIE_SQL_2026` expressions MUST NOT call `AGG` anywhere else until a future version defines it.
This version defines two uses of `AGG`, both in metrics (see [Metric Scoping](spec.md#metric-scoping)):

* A model-scoped metric may use `AGG` to evaluate a dataset-scoped metric, as in `AGG(orders.total_revenue)`. The argument is a single `dataset.metric` reference.
* A dataset-scoped metric may use `AGG` to evaluate a measure of the dataset's `source`, as in `AGG(source.total_revenue)`, when the `source` is a measure relation (see [Measure Relation as a `source`](spec.md#measure-relation-as-a-source)). The argument is a single `source.measure` reference. The call composes the measure into the metric: the measure is evaluated when a consuming query evaluates the metric, not where the metric is defined.

In both uses, the call takes no `FILTER (WHERE ...)` clause. `OSSIE_SQL_2026` expressions MUST NOT call `AGG` anywhere else until a future version defines it.

**Compatibility.** Earlier versions of this specification did not reserve `AGG`, so an older `OSSIE_SQL_2026` expression might call a different function by that name. To update it, rename that function or write the expression in a vendor dialect. Reserving `AGG` as a function name does not prevent a field, metric, or column from being named `agg`.

Expand Down Expand Up @@ -930,7 +935,8 @@ tooling aid; where it and this document differ, this document is authoritative.
|:----------|:-----------| :---- |
| 0.2.0.dev | 2026-07-15 | Initial draft |
| 0.2.0.dev | 2026-10-29 | State that function names are case insensitive. Reserve `AGG` for measure evaluation; expressions that call another function named `AGG` must rename it or move to a vendor dialect |
| 0.2.0.dev | 2026-11-06 | Allow model-scoped metrics to evaluate a dataset-scoped metric with `AGG(dataset.metric)` |
| 0.3.0.dev0 | 2026-11-06 | Allow model-scoped metrics to evaluate a dataset-scoped metric with `AGG(dataset.metric)` |
| 0.3.0.dev0 | 2026-11-20 | Allow dataset-scoped metrics to evaluate a source measure with `AGG(source.measure)` when the `source` is a measure relation |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small one: this row uses 0.3.0.dev0, and the rows above use 0.2.0.dev. The #703 row just above should also have been 0.3.0.dev, since #703 merged after #691, but I missed it. Could you relabel that row in this PR and use the same form for both? My mistake, sorry.


---

Expand Down
2 changes: 1 addition & 1 deletion core-spec/ossie-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"items": {
"$ref": "#/$defs/Metric"
},
"description": "Dataset-scoped metrics: aggregations evaluated at this dataset's row level, for measures that semantically belong to the dataset. The expression references this dataset's declared fields by single-part (unqualified) name, and columns of the dataset's source as source.column. It must resolve entirely within this dataset; an expression that must reference another dataset belongs in the model-scoped metrics instead. Within the dataset, field names and metric names share one namespace and must all be unique across the two."
"description": "Dataset-scoped metrics: measures defined on this dataset's relation that semantically belong to the dataset. A metric aggregates the dataset's rows, or derives from measures of the dataset's source. The expression references this dataset's declared fields by single-part (unqualified) name, and columns of the dataset's source as source.column. When the source is a measure relation, it may evaluate a source measure with AGG(source.measure). It must resolve entirely within this dataset; an expression that must reference another dataset belongs in the model-scoped metrics instead. Within the dataset, field names and metric names share one namespace and must all be unique across the two."
},
"nonportable_extensions": {
"type": "array",
Expand Down
4 changes: 2 additions & 2 deletions core-spec/relational_semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ SQL-native names. The correspondence:
|---|---|---|
| relation | `dataset` | A logical table (fact or dimension) exposed as a SQL relation. |
| field | `field` | A scalar (non-measure) column; we adopt Ossie's term. Ossie's optional `dimension` role (e.g. `is_time`) is metadata this interface does not require. |
| measure | dataset-scoped `metric` (`datasets[].metrics`) | An aggregate expression over the dataset's rows (of any scalar result type), exposed as a measure on the dataset's relation. Model-scoped metrics are not exposed as measure columns (Section 10.3). |
| row identity (Section 3.2) | `primary_key` | A dataset's declared primary key is a natural source of a measure's row identity. |
| measure | dataset-scoped `metric` (`datasets[].metrics`) | A measure on the dataset's relation, of any scalar result type. A dataset-scoped metric that composes measures of the dataset's `source` with `AGG(source.measure)` is a derived measure (Section 5.2), and the dataset remains a relation. The `source` must be a measure relation (see [Measure Relation as a `source`](spec.md#measure-relation-as-a-source)). Each measure of the `source` that it references keeps its own source rows and row identity, which can originate upstream of the dataset (Sections 3.2 and 3.3); its other aggregates read the dataset's rows. Model-scoped metrics are not exposed as measure columns (Section 10.3). |
| row identity (Section 3.2) | `primary_key` | A dataset's declared primary key is a natural source of the row identity of a base measure. A measure of the dataset's `source` that a derived measure evaluates keeps the row identity that it has there. |
| join relationship (Section 11.3) | `relationship` (`from`/`to`, `from_columns`/`to_columns`) | `from`/`to` map to source/target and the columns to the join predicate (`from` many, `to` one); Section 11.3 adds cardinality, roles, and arbitrary `ON`. |
| Layer 1 expression | `OSSIE_SQL_2026` expression (`expression.sql`, or an `OSSIE_SQL_2026` entry in `dialects`) | The portable form of an Ossie expression, in the Layer 1 language (Section 1.1). For the resolution rules, see [Expression Object](spec.md#expression-object). |

Expand Down
Loading
Loading