Repository navigation
docs(core-spec): Let model-scoped metrics evaluate dataset-scoped metrics with AGG() - #703
Conversation
56fd48f to
e19b363
Compare
kayemkim
left a comment
There was a problem hiding this comment.
Two things from running the validator on the branch.
The header still pins sqlglot>=30.12.0, but exp.Agg only exists from sqlglot 30.19.0. With 30.18.0 installed, every document ends in AttributeError while validating …: module 'sqlglot.expressions' has no attribute 'Agg', examples/tpcds_semantic_model.yaml included, because validate_agg_placement and validate_metric_references look for exp.Agg whether or not the text calls it. CI installs the latest sqlglot, so it does not show there; bumping the header to >=30.19.0 closes it.
The checks also reach other dialects. A SNOWFLAKE field expression AGG(x) and a SNOWFLAKE dataset-scoped metric AGG(total_usd) now fail with the [Scope] error, and a SNOWFLAKE model-scoped metric gets the argument and FILTER warnings, while expression_language.md keeps "Expressions in other dialects are not affected" and the new MUST NOT is scoped to OSSIE_SQL_2026. Both places have expression.dialect in hand, so skipping the AGG-specific messages when it is not PORTABLE_DIALECT would match the text.
Two smaller notes. A dataset-scoped metric AGG(order_revenue) is reported twice, first by validate_metric_scoping as an undeclared field order_revenue and then by the new check, and the first message points the wrong way. And AGG(orders.total_usd), AGG(DISTINCT orders.order_revenue), AGG(*) and the FILTER form each get a [Reference] warning and the document passes, while AGG in a field expression is an error, although the spec says MUST NOT for both; an observation, not a request.
The accepted shapes behave as written: agg(...), AGG(Orders.ORDER_REVENUE), the quoted form, AGG inside CASE and COALESCE and the dialects entry form pass clean, and a bare orders.order_revenue gets the new "write AGG(...)" warning. The branch conflicts with #698 and #696 in validate.py, so whichever lands second needs a rebase.
7b26364 to
c9844ba
Compare
|
Thanks @kayemkim, this was a really useful review. I've pushed c9844ba:
|
kayemkim
left a comment
There was a problem hiding this comment.
All four are in as described, so the validation side is good from me. On the merged tree the suite passes on sqlglot 30.19.0, the Snowflake cases read exactly as they do on main, a dataset-scoped AGG(order_revenue) gives the one [Scope] line, and each misuse in a model-scoped metric now fails the document. Moving those to errors changes no existing document: the examples, the compliance cases and the converter fixtures all come out the same as on main.
On ordering, this conflicts with #696 and #704 in validate.py. With #696 it is the two column loops, where your id() skip has to move into the iter_columns(tree, expression.dialect) loop that PR introduces, so whichever lands second needs a small rebase.
christianeu-db
left a comment
There was a problem hiding this comment.
Thanks @justint-db! While the dev@ lazy consensus runs until Friday, I flagged one potential text update that would be nice to address before merging
…rics with AGG() A model-scoped metric may now evaluate a dataset-scoped metric with AGG(dataset.metric), as in AGG(orders.total_revenue) / COUNT(DISTINCT customers.customer_id). The argument must be a single dataset.metric reference, and the call takes no FILTER clause. Bare metric references, AGG of a field, and AGG of a model-scoped metric remain invalid. AGG stays disallowed everywhere else. Layer 3 lowers an AGG(D.m) call as one component with home dataset D. The validator accepts AGG(dataset.metric) in model-scoped metrics and reports a misused AGG call as an error, as it does AGG in a field expression or a dataset-scoped metric. No model written before AGG was allowed can contain one. A bare metric reference stays a warning, like the other metric reference findings, with a hint toward AGG. These AGG checks apply only to OSSIE_SQL_2026, as the spec does. They need sqlglot 30.19.0, the first release with exp.Agg, so the minimum version is raised. Co-authored-by: Isaac <no-reply@databricks.com>
AGG is an aggregate function (Layer 2 Section 6), but this version does not allow a FILTER clause on it. Say so where the expression language requires every aggregate function to support FILTER. Co-authored-by: Isaac <no-reply@databricks.com>
fbffb48 to
c043609
Compare
…with AGG() A dataset-scoped metric may now evaluate a measure of its dataset's source with AGG(source.measure), as in AGG(source.total_revenue) / COUNT(DISTINCT order_id). The source must be a measure relation (Relational Query Interface, Section 3.1). A new section, Measure Relation as a source, applies that definition to a source, which is an object that an engine holds. The source is a measure relation if and only if it has at least one measure column and four conditions hold. Every query reads one multiset of rows, which does not depend on the columns that the query selects, so a query returns the same groups with no measure, one measure, or several measures. A query can group and filter every measure by every column that is not a measure. Each measure aggregates rows that are fixed where the measure is defined, with a row identity that a query does not change. A query can join the source to another relation, and each measure still aggregates each of its rows at most once in each group. The conditions apply to each source and to the results that its queries return, not to how the engine plans a query. A source whose queries return rows or groups that depend on the selected columns is not a measure relation, even if a query can name it in FROM and evaluate its metrics with AGG; the Layer 3 wide table over an Ossie semantic model is the example. A dataset still cannot use another dataset as its source. The argument must be a single source.measure reference, and the call takes no FILTER clause. A source measure cannot be referenced in any other way, and AGG cannot be called in any other way: SUM of a source measure, AGG of a field, and AGG of a metric are invalid. A field expression cannot refer to a measure column. Such a metric is a derived measure (Relational Query Interface, Section 5.2). Each measure of the source keeps the rows that it aggregates and their row identity, also when the source has measures with different row identities, so the metric keeps each one's no-duplication guarantee, including through AGG(dataset.metric). Other aggregates in the expression aggregate the dataset's rows. Section 3.4 of the Relational Query Interface now distinguishes base and derived dataset-scoped measures, and a dataset-scoped metric is described as defined on the dataset's relation rather than at its row level. The document does not declare which source columns are measures, so document validation checks only the form of each AGG call. A consumer that generates SQL against the dataset's source checks the rest. Source metadata shows which columns are measures, and the consumer decides from the engine's documented behavior whether the source is a measure relation. The consumer rejects an AGG argument that is not a measure of a measure relation, and a field or a source.column outside AGG that is a measure, rather than reading the measure as an ordinary column or substituting an ordinary aggregate. It may reject a measure relation that it does not support. A consumer that does not read the source cannot check these rules. The validator accepts AGG(source.measure) in dataset-scoped metrics and reports any other AGG call there as an error. These checks apply only to OSSIE_SQL_2026. This change also adds the docs/spec_changes.md row for apache#703. Co-authored-by: Isaac <no-reply@databricks.com>
…with AGG() A dataset-scoped metric may now evaluate a measure of its dataset's source with AGG(source.measure), as in AGG(source.total_revenue) / COUNT(DISTINCT order_id). The source must be a measure relation (Relational Query Interface, Section 3.1). A new section, Measure Relation as a source, applies that definition to a source, which is an object that an engine holds. The source is a measure relation if and only if it has at least one measure column and four conditions hold. Every query reads one multiset of rows, which does not depend on the columns that the query selects, so a query returns the same groups with no measure, one measure, or several measures. A query can group and filter every measure by every column that is not a measure. Each measure aggregates rows that are fixed where the measure is defined, with a row identity that a query does not change. A query can join the source to another relation, and each measure still aggregates each of its rows at most once in each group. The conditions apply to each source and to the results that its queries return, not to how the engine plans a query. A source whose queries return rows or groups that depend on the selected columns is not a measure relation, even if a query can name it in FROM and evaluate its metrics with AGG; the Layer 3 wide table over an Ossie semantic model is the example. A dataset still cannot use another dataset as its source. The argument must be a single source.measure reference, and the call takes no FILTER clause. A source measure cannot be referenced in any other way, and AGG cannot be called in any other way: SUM of a source measure, AGG of a field, and AGG of a metric are invalid. A field expression cannot refer to a measure column. Such a metric is a derived measure (Relational Query Interface, Section 5.2). Each measure of the source keeps the rows that it aggregates and their row identity, also when the source has measures with different row identities, so the metric keeps each one's no-duplication guarantee, including through AGG(dataset.metric). Other aggregates in the expression aggregate the dataset's rows. Section 3.4 of the Relational Query Interface now distinguishes base and derived dataset-scoped measures, and a dataset-scoped metric is described as defined on the dataset's relation rather than at its row level. The document does not declare which source columns are measures, so document validation checks only the form of each AGG call. A consumer that generates SQL against the dataset's source checks the rest. Source metadata shows which columns are measures, and the consumer decides from the engine's documented behavior whether the source is a measure relation. The consumer rejects an AGG argument that is not a measure of a measure relation, and a field or a source.column outside AGG that is a measure, rather than reading the measure as an ordinary column or substituting an ordinary aggregate. It may reject a measure relation that it does not support. A consumer that does not read the source cannot check these rules. The validator accepts AGG(source.measure) in dataset-scoped metrics and reports any other AGG call there as an error. These checks apply only to OSSIE_SQL_2026. This change also adds the docs/spec_changes.md row for apache#703. Co-authored-by: Isaac <no-reply@databricks.com>
…with AGG() A dataset-scoped metric may now evaluate a measure of its dataset's source with AGG(source.measure), as in AGG(source.total_revenue) / COUNT(DISTINCT order_id). The source must be a measure relation (Relational Query Interface, Section 3.1). A new section, Measure Relation as a source, applies that definition to a source, which is an object that an engine holds. The source is a measure relation if and only if it has at least one measure column and four conditions hold. Every query reads one multiset of rows, which does not depend on the columns that the query selects, so a query returns the same groups with no measure, one measure, or several measures. A query can group and filter every measure by every column that is not a measure. Each measure aggregates rows that are fixed where the measure is defined, with a row identity that a query does not change. A query can join the source to another relation, and each measure still aggregates each of its rows at most once in each group. The conditions apply to each source and to the results that its queries return. A source whose queries return rows or groups that depend on the selected columns is not a measure relation, even if a query can name it in FROM and evaluate its metrics with AGG; the Layer 3 wide table over an Ossie semantic model is the example. A dataset still cannot use another dataset as its source. The argument must be a single source.measure reference, and the call takes no FILTER clause. A source measure cannot be referenced in any other way, and AGG cannot be called in any other way: SUM of a source measure, AGG of a field, and AGG of a metric are invalid. A field expression cannot refer to a measure column. Such a metric is a derived measure (Relational Query Interface, Section 5.2). Each measure of the source keeps the rows that it aggregates and their row identity, also when the source has measures with different row identities, so the metric keeps each one's no-duplication guarantee, including through AGG(dataset.metric). Other aggregates in the expression aggregate the dataset's rows. Section 3.4 of the Relational Query Interface now distinguishes base and derived dataset-scoped measures, and a dataset-scoped metric is described as defined on the dataset's relation rather than at its row level. The document does not declare which source columns are measures, so document validation checks only the form of each AGG call. A consumer that generates SQL against the dataset's source checks the rest. Source metadata shows which columns are measures, and the consumer decides whether the source is a measure relation. The consumer rejects an AGG argument that is not a measure of a measure relation, and a field or a source.column outside AGG that is a measure, rather than reading the measure as an ordinary column or substituting an ordinary aggregate. It may reject a measure relation that it does not support. A consumer that does not read the source cannot check these rules. The validator accepts AGG(source.measure) in dataset-scoped metrics and reports any other AGG call there as an error. These checks apply only to OSSIE_SQL_2026. This change also adds the docs/spec_changes.md row for apache#703. Co-authored-by: Isaac <no-reply@databricks.com>
…with AGG() A dataset-scoped metric may now evaluate a measure of its dataset's source with AGG(source.measure), as in AGG(source.total_revenue) / COUNT(DISTINCT order_id). The source must be a measure relation (Relational Query Interface, Section 3.1). A new section, Measure Relation as a source, applies that definition to a source, which is an object that an engine holds. The source is a measure relation if and only if it has at least one measure column and four conditions hold. Every query reads one multiset of rows, which does not depend on the columns that the query selects, so a query returns the same groups with no measure, one measure, or several measures. A query can group and filter every measure by every column that is not a measure. Each measure aggregates rows that are fixed where the measure is defined, with a row identity that a query does not change. A query can join the source to another relation, and each measure still aggregates each of its rows at most once in each group. The conditions apply to each source and to the results that its queries return. A source whose queries return rows or groups that depend on the selected columns is not a measure relation, even if a query can name it in FROM and evaluate its metrics with AGG; the Layer 3 wide table over an Ossie semantic model is the example. A dataset still cannot use another dataset as its source. The argument must be a single source.measure reference, and the call takes no FILTER clause. A source measure cannot be referenced in any other way, and AGG cannot be called in any other way: SUM of a source measure, AGG of a field, and AGG of a metric are invalid. A field expression cannot refer to a measure column. Such a metric is a derived measure (Relational Query Interface, Section 5.2). Each measure of the source keeps the rows that it aggregates and their row identity, also when the source has measures with different row identities, so the metric keeps each one's no-duplication guarantee, including through AGG(dataset.metric). Other aggregates in the expression aggregate the dataset's rows. Section 3.4 of the Relational Query Interface now distinguishes base and derived dataset-scoped measures, and a dataset-scoped metric is described as defined on the dataset's relation rather than at its row level. The document does not declare which source columns are measures, so document validation checks only the form of each AGG call. A consumer that generates SQL against the dataset's source must not read a measure as an ordinary column or replace AGG with an ordinary aggregate, and may reject a source that it does not support. The validator accepts AGG(source.measure) in dataset-scoped metrics and reports any other AGG call there as an error. These checks apply only to OSSIE_SQL_2026. This change also adds the docs/spec_changes.md row for apache#703. Co-authored-by: Isaac <no-reply@databricks.com>
…with AGG() A dataset-scoped metric may now evaluate a measure of its dataset's source with AGG(source.measure), as in AGG(source.total_revenue) / COUNT(DISTINCT order_id). The source must be a measure relation (Relational Query Interface, Section 3.1). A new section, Measure Relation as a source, applies that definition to a source, which is an object that an engine holds. The source is a measure relation if and only if it has at least one measure column and four conditions hold. Every query reads one multiset of rows, which does not depend on the columns that the query selects, so a query returns the same groups with no measure, one measure, or several measures. A query can group and filter every measure by every column that is not a measure. Each measure aggregates rows that are fixed where the measure is defined, with a row identity that a query does not change. A query can join the source to another relation, and each measure still aggregates each of its rows at most once in each group. The conditions apply to each source and to the results that its queries return. A source whose queries return rows or groups that depend on the selected columns is not a measure relation, even if a query can name it in FROM and evaluate its metrics with AGG; the Layer 3 wide table over an Ossie semantic model is the example. A dataset still cannot use another dataset as its source. The argument must be a single source.measure reference, and the call takes no FILTER clause. A source measure cannot be referenced in any other way, and AGG cannot be called in any other way: SUM of a source measure, AGG of a field, and AGG of a metric are invalid. A field expression cannot refer to a measure column. Such a metric is a derived measure (Relational Query Interface, Section 5.2). Each measure of the source keeps the rows that it aggregates and their row identity, also when the source has measures with different row identities, so the metric keeps each one's no-duplication guarantee, including through AGG(dataset.metric). Other aggregates in the expression aggregate the dataset's rows. Section 3.4 of the Relational Query Interface now distinguishes base and derived dataset-scoped measures, and a dataset-scoped metric is described as defined on the dataset's relation rather than at its row level. The document does not declare which source columns are measures, so document validation checks only the form of each AGG call. A consumer that generates SQL against the dataset's source must not read a measure as an ordinary column or replace AGG with an ordinary aggregate, and may reject a source that it does not support. The validator accepts AGG(source.measure) in dataset-scoped metrics and reports any other AGG call there as an error. These checks apply only to OSSIE_SQL_2026. This change also adds the docs/spec_changes.md row for apache#703. Co-authored-by: Isaac <no-reply@databricks.com>
…eferences Address review feedback on AGG(source.measure): - Rule 9: a consumer that generates SQL against the source MUST reject a source measure outside AGG, and AGG on a column that is not a measure. Update the docs/spec_changes.md row to match. - Shorten the paragraph on why the Layer 3 wide table is not a measure relation. - Wide Table Query Interface, Section 5.2: state that a dataset-scoped metric that calls AGG(source.measure) is still one component. - Label the apache#703 row of the expression language change log 0.3.0.dev0. Co-authored-by: Isaac <no-reply@databricks.com>
apache/ossie#703 lets a model's metric call AGG(dataset.metric): a single reference to a dataset's metric, without FILTER, evaluated as that metric (wide_table_semantics.md section 5.2). The planner now expands the call into the dataset's metric as a question naming it would resolve it, so it keeps its dataset as the home of every aggregate, COUNT(*) included, and its value over no rows. parse() checks the shape of every call and also refuses OVER on it; untranslatable() refuses AGG in a field or a dataset's metric, and the planner refuses it in a filter, naming the dataset's metric to write instead. A model's metric is hidden with any dataset's metric it evaluates, and no server's function list hides it for calling AGG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…trics cannot reference metrics Since apache#703 a model-scoped metric may evaluate a dataset-scoped metric with AGG(dataset.metric). Reword the M5 fixture comment, the manifest construct and the README row. Co-authored-by: Isaac <no-reply@databricks.com>
…form of M3 (#631) * test(compliance): add portability rung M6, date and time scalars One dataset with YEAR and DATE_TRUNC fields and an AVG(DATEDIFF(...)) metric, using the part-first DATEDIFF(part, start, end) order from expression_language.md. Adds one construct on top of the baseline. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): add the FILTER (WHERE ...) form to portability rung M3 expression_language.md makes the aggregate FILTER (WHERE ...) clause REQUIRED. Two variants (qualified and bare) express the same filtered aggregate as the existing CASE WHEN fixtures, so a difference between the two forms isolates handling of the clause itself. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): add portability rung M4, a cross-dataset metric Two datasets joined by a declared relationship and one model-scoped metric that aggregates across the join (SUM over one dataset divided by a COUNT DISTINCT over the other), referencing fields as dataset.field. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): add portability rung M5, metric-to-metric composition A model-scoped metric (avg_order_value) composed from two other model-scoped metrics referenced by name, per Metric Scoping in core-spec/spec.md. Co-authored-by: Isaac <no-reply@databricks.com> * docs(compliance): describe portability rungs M0-M6 Lists the M3 FILTER (WHERE ...) form and rungs M4-M6 in the README table, notes that M7 and M8 wait on the window ORDER BY NULL-placement default, and records that the fixtures live in this repository. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): cover M4-M6 in the identity test, name every element by kind and name Follow-ups from the review of #631: - The identity regression test looped over M0-M3 only; it now covers M0-M6, and the grader README says so. - M5's reference_form_primary said "qualified", but its only variant (the composite under test) references metric names; it is now "metric-name". - M6 named "fields and metric" with a comma-joined name, and M2 named "metrics" without a name, so a lookup by kind and name found neither. Every rung now lists elements_under_test, each with one kind (metric or field) and one name. Two new tests keep the manifest honest: every listed element is found by kind and name in each variant of its rung, and each primary variant uses the rung's primary reference form. Both fail on the previous manifest. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): carry M5's composition inlined, as the spec requires A metric expression cannot refer to other metrics (core-spec/spec.md, Metric Scoping; expression_language.md), and since #608 validate.py warns when one does. M5's composite, avg_order_value = total_amount / order_count, referenced the two metrics by name. The "Referenced as metric_name" row in the Metric Scoping table is how a query addresses a metric, not what an expression may contain. M5 now carries the composition the way a converter has to emit it when the source tool composes measures: the parts inlined, over qualified dataset.field references, SUM(sales.amount) / NULLIF(COUNT(sales.order_id), 0), NULL when there are no orders. The two base metrics stay alongside it. The fixture validates with no warnings on main's validator, and its primary reference form is qualified again. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): write M3's CASE form without ELSE 0, as the FILTER form means expression_language.md (Conditional Aggregations) states that FILTER (WHERE ...) is equivalent to a CASE with no ELSE for an aggregate that ignores NULL, and that an ELSE 0 "would count as a real row". M3's CASE fixtures wrote ELSE 0, so on rows that exist but do not match they give 0 where the FILTER variants added here give NULL; they were not the same aggregate the rung describes. Found by idk-arsh's execution check on apache/ossie-converters#24. Both CASE fixtures now read SUM(CASE WHEN ... THEN amount END), which also matches DAX (CALCULATE over no rows is BLANK). All four M3 fixtures validate on main. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): carry the bare variants as dataset-scoped metrics, grade them Since #486 a model-scoped metric must reference fields as dataset.field, and since #608 validate.py warns on the bare variants of M0, M2 and M3 ("is not qualified"). Metric Scoping in core-spec/spec.md gives the bare form its place: a dataset-scoped metric (datasets[].metrics) references its own dataset's fields by single-part name. The four bare fixtures now carry their metrics there, and validate without warnings on main. The grader read only the model-root metrics, so a dataset-scoped metric was not graded at all, and the identity test still passed. It now collects datasets[].metrics too, keyed dataset.metric as the spec references them, and the identity test asserts that every metric in a fixture is graded. New tests: a dataset-scoped metric graded PORTABLE, dropped, and moved to the model (REWRITTEN, identity not preserved). All four fail without the grader change. Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): name manifest elements by the grader's keys; spec spelling in M6 Follow-ups from the second review of #631: - The manifest named fields bare (amount_with_tax, order_year, order_month_start), but the grader reports a field as dataset.field, so matching manifest elements to findings found no result for M1 or M6. Fields are now named sales.<field>, and a variant that carries the rung's metrics as dataset-scoped metrics says so with metrics_in: sales (the grader reports those as sales.<metric>). The manifest test now uses the grader's own _collect keys instead of building a name set of its own, so the two cannot drift apart; it fails on the previous manifest. - M6 wrote DATEDIFF('day', ...), the Tableau spelling in the mapping table; the spec writes the part as a keyword, DATEDIFF(day, ...). Co-authored-by: Isaac <no-reply@databricks.com> * docs(compliance): point the portability ladder at apache/ossie-converters#24 Issue #576 was transferred to apache/ossie-converters#24 with the converters; the ladder, grader and manifest still cited the old number, which now resolves to nothing. Co-authored-by: Isaac <no-reply@databricks.com> * fix(compliance): keep the dataset qualifier on a field two datasets declare M4 is the first rung with two datasets, and customer_id is declared by both sales and customers. The grader stripped every table qualifier before comparing trees, so a converter that re-pointed COUNT(DISTINCT customers.customer_id) to sales.customer_id, or dropped the qualifiers, was graded as a cosmetic rewrite, and _repair_by_expression paired such a renamed metric as expression-equivalent. _ambiguous_fields() reads the field names that more than one input dataset declares; for those the qualifier is kept, for all others it is stripped as before (M0-M3 have one dataset each, so their grades do not change). Three regression tests; two fail on the previous grader. Suggested-by: Jean-Baptiste Onofré <jbonofre@apache.org> Co-authored-by: Isaac <no-reply@databricks.com> * test(compliance): move the M3-M6 fixtures to spec version 0.3.0.dev0 main moved the in-development version to 0.3.0.dev0 (#691), and the schema pins it, so the fixtures this PR adds declare it too. Co-authored-by: Isaac <no-reply@databricks.com> * fix(compliance): resolve a dataset qualifier against the dataset that declares the field Review of #631. The shared-field rule kept or dropped a qualifier by the field name alone, so a field requalified with its own dataset needed review when another dataset declared the name too, and a metric that named a dataset not declaring the field was cosmetic. Each column is now resolved to the dataset it names before the trees are compared: a bare name in a field expression or dataset-scoped metric is the element's own dataset, elsewhere the one dataset that declares it, and a written qualifier is kept as written. Co-authored-by: Isaac <no-reply@databricks.com> * fix(compliance): treat a returned dataset with an authored dataset's source as that dataset A converter that names a dataset after its source table (lightdash returns orders for an authored sales over samples.sales.orders) renamed it. Since qualifiers are kept as written, its metrics and fields were graded as dropped plus an unrelated addition. Map the renamed dataset's qualifiers on the returned side to the authored dataset before resolving, when exactly one authored dataset has that source. The 120 cases of the latest Interop matrix run now grade as on main. Adds a test built from lightdash's real M0 return. Co-authored-by: Isaac <no-reply@databricks.com> * docs(compliance): M5 carries composition inlined, without claiming metrics cannot reference metrics Since #703 a model-scoped metric may evaluate a dataset-scoped metric with AGG(dataset.metric). Reword the M5 fixture comment, the manifest construct and the README row. Co-authored-by: Isaac <no-reply@databricks.com> --------- Co-authored-by: Isaac <no-reply@databricks.com>
….metric) Since apache#703 a model-scoped metric may evaluate a dataset-scoped metric with AGG(dataset.metric). M5.agg_ref composes the same avg_order_value from two dataset-scoped base metrics that way, tagged OSSIE_SQL_2026, next to the inlined primary. A converter that expands the AGG grades as review. Co-authored-by: Isaac <no-reply@databricks.com>
….metric) Since apache#703 a model-scoped metric may evaluate a dataset-scoped metric with AGG(dataset.metric). M5.agg_ref composes the same avg_order_value from two dataset-scoped base metrics that way, tagged OSSIE_SQL_2026, next to the inlined primary. A converter that expands the AGG grades as review. Co-authored-by: Isaac <no-reply@databricks.com>
…with AGG() (#726) * docs(core-spec): Let dataset-scoped metrics evaluate source measures with AGG() A dataset-scoped metric may now evaluate a measure of its dataset's source with AGG(source.measure), as in AGG(source.total_revenue) / COUNT(DISTINCT order_id). The source must be a measure relation (Relational Query Interface, Section 3.1). A new section, Measure Relation as a source, applies that definition to a source, which is an object that an engine holds. The source is a measure relation if and only if it has at least one measure column and four conditions hold. Every query reads one multiset of rows, which does not depend on the columns that the query selects, so a query returns the same groups with no measure, one measure, or several measures. A query can group and filter every measure by every column that is not a measure. Each measure aggregates rows that are fixed where the measure is defined, with a row identity that a query does not change. A query can join the source to another relation, and each measure still aggregates each of its rows at most once in each group. The conditions apply to each source and to the results that its queries return. A source whose queries return rows or groups that depend on the selected columns is not a measure relation, even if a query can name it in FROM and evaluate its metrics with AGG; the Layer 3 wide table over an Ossie semantic model is the example. A dataset still cannot use another dataset as its source. The argument must be a single source.measure reference, and the call takes no FILTER clause. A source measure cannot be referenced in any other way, and AGG cannot be called in any other way: SUM of a source measure, AGG of a field, and AGG of a metric are invalid. A field expression cannot refer to a measure column. Such a metric is a derived measure (Relational Query Interface, Section 5.2). Each measure of the source keeps the rows that it aggregates and their row identity, also when the source has measures with different row identities, so the metric keeps each one's no-duplication guarantee, including through AGG(dataset.metric). Other aggregates in the expression aggregate the dataset's rows. Section 3.4 of the Relational Query Interface now distinguishes base and derived dataset-scoped measures, and a dataset-scoped metric is described as defined on the dataset's relation rather than at its row level. The document does not declare which source columns are measures, so document validation checks only the form of each AGG call. A consumer that generates SQL against the dataset's source must not read a measure as an ordinary column or replace AGG with an ordinary aggregate, and may reject a source that it does not support. The validator accepts AGG(source.measure) in dataset-scoped metrics and reports any other AGG call there as an error. These checks apply only to OSSIE_SQL_2026. This change also adds the docs/spec_changes.md row for #703. Co-authored-by: Isaac <no-reply@databricks.com> * docs(core-spec): Address review feedback on AGG(source.measure) - Reject an empty quoted identifier, as in AGG(source.""), and test it. - Update the validate_metric_scoping comment: validate_agg_placement now accepts AGG(source.measure) and reports any other form. - Use 0.3.0.dev0 in the expression language change log row. - Date the expression language change log row and the #726 row in docs/spec_changes.md 2026-11-20, the merge date. Co-authored-by: Isaac <no-reply@databricks.com> * docs(core-spec): Require consumers to reject invalid source measure references Address review feedback on AGG(source.measure): - Rule 9: a consumer that generates SQL against the source MUST reject a source measure outside AGG, and AGG on a column that is not a measure. Update the docs/spec_changes.md row to match. - Shorten the paragraph on why the Layer 3 wide table is not a measure relation. - Wide Table Query Interface, Section 5.2: state that a dataset-scoped metric that calls AGG(source.measure) is still one component. - Label the #703 row of the expression language change log 0.3.0.dev0. Co-authored-by: Isaac <no-reply@databricks.com> * docs: Align docs/index.md with the dataset-scoped metric definition Address review feedback on AGG(source.measure): the Metrics row under "Specification at a Glance" and the Metric row in the Glossary now say that a dataset-scoped metric is defined on the dataset's relation, as spec.md, spec.yaml and the schema description do. Co-authored-by: Isaac <no-reply@databricks.com> --------- Co-authored-by: Isaac <no-reply@databricks.com>
Summary
A model-scoped metric can now evaluate a dataset-scoped metric with
AGG(dataset.metric):This is the first place model declarations may use
AGG, which #662 reserved for a future version.Rules (
spec.mdMetric Scoping rule 6 and Name Resolution,expression_language.mdName Spaces and Measure Evaluation:AGG)dataset.metricreference to a dataset-scoped metric.FILTER (WHERE ...)clause.orders.total_revenue,AGGof a field (fields are never measures), andAGGof a model-scoped metric.AGGstays disallowed everywhere else, including field expressions and dataset-scoped metrics.Within a dataset, field and metric names share one namespace, so
orders.total_revenuealways names exactly one thing.Deferred: model-scoped metrics referring to other model-scoped metrics,
FILTERonAGG, andAGGover a source measure in dataset-scoped metrics.Layer 3 (
wide_table_semantics.md§5.2): one sentence saying that anAGG(D.m)call is one component with home datasetD, evaluated as the dataset-scoped metricD.m. This matches how §5.2 already treats a dataset-scoped metric queried directly.Validator (
validation/validate.py)AGG(dataset.metric). It warns on a bare metric reference (suggesting theAGGform),AGGof a field or a model-scoped metric, an argument that isn't a single qualified reference, an unknown dataset or metric, andAGGwithFILTER. These are warnings, like the rest of that check.AGGin a field expression or a dataset-scoped metric as an error, since the spec says MUST NOT.spec.yamlandossie-schema.jsondescriptions are updated to match.Related Issues
Follows #662 (reserve
AGG), #633 (source columns), and #653 (Layer 3).Checklist
Specification
core-spec/and follow the existing structureValidation
validation/are updated if the spec changedTests
validation/tests/: 579 passed;python/tests/: 269 passed)This pull request and its description were written by Isaac.