Skip to content

feature(core-spec): Reserve METRIC() for metric definition - #774

Open
christianeu-db wants to merge 3 commits into
apache:mainfrom
christianeu-db:reserve-metric-function
Open

christianeu-db wants to merge 3 commits into
apache:mainfrom
christianeu-db:reserve-metric-function

Conversation

@christianeu-db

@christianeu-db christianeu-db commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reserve METRIC() in OSSIE_SQL_2026 as the counterpart to AGG() in the Layer 2 Relational Query Interface:

  • METRIC(<aggregate expression>) defines a measure without evaluating it.
  • AGG(measure) evaluates a measure in the consuming query.
  • METRIC() is permitted only as a complete select item in an unaggregated SELECT.

Dataset-scoped metric expressions remain unchanged: the metrics declaration implicitly defines a measure, so SUM(amount) is valid without an explicit METRIC() wrapper.

This replaces the previously proposed TO MEASURE syntax. The function form makes the operand boundary explicit and provides a symmetric definition/evaluation pair.

Scope

This PR updates the Layer 1 reservation and the Layer 2 proposal. It introduces no new YAML constructs or changes to existing dataset declarations.

Validator enforcement will follow separately, consistent with the earlier AGG() reservation (#662).

Related

Specification

  • Spec changes are included in core-spec/ and follow the existing structure
  • Spec changes have a [DISCUSS] thread on dev@ with a stated end date, and reach lazy consensus (or pass a [VOTE]) before merge - https://lists.apache.org/thread.html/9hnv6x6jv9vqoycp5d0mqs1gkj22482p
  • Breaking changes to the spec are clearly called out in the summary
  • For a material spec change, docs/spec_changes.md records rationale, compatibility and migration impact, or the PR explains why no entry is needed - keyword was not reserved prior

AI disclosure

Per the ASF Generative Tooling Guidance, this contribution was prepared with AI assistance. I have reviewed and verified every change.

christianeu-db added a commit to christianeu-db/ossie that referenced this pull request Nov 20, 2026
Co-authored-by: Isaac <no-reply@databricks.com>
Reserve the function name METRIC in OSSIE_SQL_2026 for metric definition,
as the counterpart of AGG: METRIC defines a measure, and AGG evaluates
one. OSSIE_SQL_2026 expressions must not call METRIC. A dataset-scoped
metric's expression is the operand of METRIC, because the metrics
declaration already defines the measure, so SUM(amount) needs no
METRIC() wrapper. The reservation applies only to OSSIE_SQL_2026.

In the Relational Query Interface, propose METRIC(<aggregate expression>)
AS name in place of the TO MEASURE marker. Define its signature,
operand, kind, and placement: METRIC is not an aggregate function, so
the aggregates in its operand stay unevaluated and do not make the
query aggregated, and METRIC() is permitted only as a complete select
item of an unaggregated SELECT. Update the examples, and record in
Appendix D why a function call replaces the postfix marker.

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db
christianeu-db force-pushed the reserve-metric-function branch from 49fe316 to 0645c87 Compare November 20, 2026 04:48
@christianeu-db christianeu-db changed the title docs(core-spec): Reserve METRIC() for metric definition feature(core-spec): Reserve METRIC() for metric definition Nov 20, 2026
@christianeu-db
christianeu-db marked this pull request as ready for review November 20, 2026 04:56
christianeu-db and others added 2 commits November 21, 2026 22:57
Resolve conflicts with apache#726 (AGG(source.measure) in dataset-scoped
metrics):

- expression_language.md: keep upstream's AGG row and add the METRIC
  row to "Not Supported in Expressions"; keep upstream's version rows
  and add the METRIC row after them.
- relational_semantics.md: take upstream's Section 3.4 measure row and
  add that the metric's expression is the operand of METRIC().
- docs/spec_changes.md: keep the apache#726 entry before the apache#774 entry.

Co-authored-by: Isaac <no-reply@databricks.com>
- relational_semantics.md Section 5.1: state that this version has no
  anonymous measures, and that relaxing the placement rule is additive.
- relational_semantics.md Appendix D: record that METRIC is not a
  function or reserved word in the engines checked.
- expression_language.md: add a Compatibility paragraph for METRIC, as
  for AGG; a field, metric, or column can still be named metric.
- ost/docs/ost.md: createView defines measures with METRIC(), not
  TO MEASURE AS.

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db

Copy link
Copy Markdown
Contributor Author

To respond to JB's feedback on https://lists.apache.org/thread.html/hb6xvjbch7lwp1hl8ytdt64034nt577o:

  1. Section 5.1 now says this version has no anonymous measures (no METRIC() inside an expression, such as an AGG() argument), and that relaxing the rule later is additive.
  2. Added a Compatibility paragraph to the METRIC section: the reservation covers only the function name, so a field, metric, or column can still be named metric.
  3. Updated ost/docs/ost.md to METRIC(). The Tableau example will follow separately.
  4. Appendix D now notes that METRIC is not a function or reserved word in Databricks, DuckDB, Snowflake, BigQuery, PostgreSQL, or Trino; only the plural METRICS appears (Snowflake semantic views, BigQuery ML.METRICS).
  5. Agreed. I'll keep feature(core-spec): Reserve METRIC() for metric definition #774 to METRIC() and raise the measure-to-metric rename in a separate thread and PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant