Repository navigation
feat(core-spec): name a dataset-scoped metric's column by its reference (breaking) - #778
Open
ZmeiGorynych wants to merge 3 commits into
Open
ZmeiGorynych wants to merge 3 commits into
ZmeiGorynych wants to merge 3 commits into
Conversation
…ce (breaking) In Layer 3, the output name of an unaliased dataset-scoped metric is its reference, `dataset.metric`, instead of the metric name alone. Fields and model-scoped metrics keep their output names. Two output names are equal when they have the same parts under identifier normalization. The worked examples, the Section 5.5 plan, Appendix B.2 and the wide-table compliance cases are updated; docs/spec_changes.md records the change.
orders and returns both declare total_amount; the query runs, with the columns orders.total_amount and returns.total_amount.
16 of 18 tasks
|
Thank you for your first contribution to Apache Ossie (incubating)! A committer will review your PR. In the meantime, please ensure:
No ICLA is required to contribute. If you are elected as a committer in the future, you will need an Individual Contributor License Agreement (ICLA) on file with the ASF. Questions? Ask in the PR comments or join us on Slack. We appreciate your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Layer 3 (
core-spec/wide_table_semantics.md), an unaliased dataset-scoped metric's output name becomes its reference,dataset.metric, instead of the metric name alone:{"dimensions": ["customers.region"], "metrics": ["orders.total_revenue", "returns.total_returns"]}Fields keep the final part of their reference (
customers.region→region), and model-scoped metrics keep their name. Uniqueness (E_NAME_COLLISION) compares output names part by part under identifier normalization. A binding that labels columns with identifiers writes a two-part name as one delimited identifier, such as"orders.total_revenue"in SQL.Breaking within unreleased
0.3.0.dev0. Unaliased dataset-scoped metric columns get new labels. Query semantics, rows and values don't change.Rationale
1. The final-part rule for metrics comes from the time when every metric was model-scoped. #246 (Foundational Semantics) left
dataset.fieldresult names to engines, and said metrics "do not have this ambiguity (the result column is the metric's name...)". That was true then: "Every metric lives in one global namespace" (#246 §4.6), and dataset-scoped metrics were deferred. #591 added dataset-scoped metrics, whose names are unique only within their dataset (Metric Scoping, rule 4). #653 then applied the final-part rule to metrics and fields alike. As far as I can find, no reasoning was recorded for metrics: it isn't in #653's review or in its[DISCUSS]thread on dev@.2. The final part drops what makes a dataset-scoped metric unique. Its reference,
dataset.metric, is its only unique name; the metric name alone is not. A column labelledtotal_amountcan't be traced back to its metric without the query, whileorders.total_amountcan.3. The current rule makes a modelling pattern the spec allows collide. Metric names are unique only within each dataset, so two datasets can both declare
total_amount,row_count,item_countand so on. #343's proposal said so outright ("two datasets MAY each declare item_count"). §3.3 uses this exact pattern as its collision example:orders.total_amountandreturns.total_amountmust be aliased. Every query across two fact datasets with conventionally named metrics hitsE_NAME_COLLISION, which matters most for agents generating queries.4. Model-scoped and dataset-scoped metrics may share a name. Nothing in Metric Scoping or the validator forbids a model-scoped
total_revenuenext toorders.total_revenue. Their references differ, but under the final-part rule their columns collide.5. It matches how metrics are referenced elsewhere. Consumers query a dataset-scoped metric as
dataset.metric, and model-scoped metrics evaluate it asAGG(dataset.metric). The label is now the same string.Fields are deliberately unchanged. #246 noted that engines name
dataset.fieldresult columns differently, and the leaf name is the common SQL convention. Dimensions such asregionare usually conformed attributes, where the leaf is the natural label. Fields can collide too (customers.regionandstores.region), but changing them is a larger, separate question. This PR only changes the case where the original premise of the rule no longer holds.Prior art
These are the semantic layers I checked in which two datasets can declare metrics of the same name and both can appear in one query. Almost all of them keep the two result columns apart by qualifying them:
orders.count), Looker's JSON results (orders.count), Omni (orders.count), Lightdash (orders_count) and Honeydew (orders.count).orders.totaltoorders_total, with a warning. This arrived in June 2026; before that, the collision was an error. Boring Semantic Layer requires the qualified spelling when short names collide, and keeps that spelling in the output.table.namein the reference when names collide, but name output columns with "the unqualified names of the metrics and dimensions". Its documented example, two dimensions both calledname, returns two columns labelledNAME, and the consumer has to alias them. OnlySHOW COLUMNSlists ambiguous names qualified.Systems whose metric names are unique across the whole model, such as dbt MetricFlow, AtScale SML and Power BI, label metrics by their bare name, as #246 did. They have no collision to resolve.
Qualifying only on collision makes a column's name depend on the other entries in the query: adding
returns.total_amountwould rename the column oforders.total_amount. Layer 3 can't leave duplicate labels either, because output names MUST be unique. Always qualifying dataset-scoped metrics avoids both problems.Survey of 17 semantic layers: how metric result columns are labelled (sources per row)
Checked on 2026-11-20 against official docs, API references and source code. "Unverified" means no such source settled the point. A dataset name that is part of the metric's own name (Snowflake's
CUSTOMER_ORDER_COUNT) does not count as a prefix.Dataset-scoped metrics, same names allowed
CUSTOMER_ORDER_COUNT),ASalias. Documented same-named dimensions: twoNAMEcolumns, docs say to alias. No same-named metric pair shown.SHOW COLUMNSlists ambiguous names asorders.revenuecarrier_count);name is …renames. Colliding dotted reference auto-renamed tocarriers_carrier_countwith a warning (since 2026-06; error before)users.count, no alias. SQL API: barecountorASalias. Views:users_citywithprefix: truejson:dashboard.count.csv/json_label: "Dashboard Count" (renamable label). SQL interface: metadataorders.amount, result columns unverifiedjsonmandated; labels optionalinventory_items.count; no rename option found. UI export unverifiedorders_count. CSV / XLSX: label, table name only withshowTableNames;customLabelsoverrideslineitems.daily_revenue_contribution(example output). SQL interface unverifiedcountScoped per view, one view per query (same-named metrics never meet)
measuresof one metric viewAS total_records);ASallowedSUM(amount) AS revenue)Metric names unique across the model (no collision to resolve)
ORDER_TOTAL;alias=unique_nameor per-modelquery_name[Sales]; REST executeQueries:[MyNewColumn]localIdentifierplus metric titleAlternatives considered
E_NAME_COLLISIONis a MUST, so output names have to be deterministic. If some engines prefix and others don't, the same query either collides or runs depending on the engine. That defeats the point of a shared Layer 3.orders_total_revenue). No quoting needed, but the label can clash with real names (orders_total+revenuevsorders+total_revenue), and it no longer equals the reference.Changes
core-spec/wide_table_semantics.md: the §3.3 output-name table, the uniqueness rule and the delimited-label guidance; the §1.3 example, the §5.5 plan and the Appendix B.2 result table.compliance/wide_table/: the expected headers andquery.ossie.sqloutput aliases of the 17 cases with unaliased dataset-scoped metrics (a01–a06, a10, a11, a13–a21). The README example table is updated too. Rows and values are unchanged.a22_same_metric_name: the retail fixture gainsorders.total_amountandreturns.total_amount, bothSUM(amount). Querying both by region returns the columnsorders.total_amountandreturns.total_amountinstead of raisingE_NAME_COLLISION. The new metrics don't affect any other case, and the fixtures passmake compliance-validate.docs/spec_changes.md: an entry with rationale and impact. Its date is a placeholder, to fill in at merge.Related Issues
Relates to #653 (Layer 3), #591 (dataset-scoped metrics), #246 (Foundational Semantics).
Checklist
Specification
core-spec/and follow the existing structure[DISCUSS]thread ondev@with a stated end date, and reach lazy consensus (or pass a[VOTE]) before merge — thread:docs/spec_changes.mdrecords rationale, compatibility and migration impactOntology
ontology/are consistent with spec changes (none needed)Converters
Validation
validation/are updated if the spec changed (no Layer 3 query validation exists)Documentation
docs/is updated to reflect any user-facing changesCONTRIBUTING.mdis updated if the contribution process changed (n/a)Examples
examples/are added or updated for any new spec constructs (n/a)Tests
pytest/ CI green)Compliance
NOTICEand/orLICENSEhave been updated (n/a)AI disclosure
Per the ASF Generative Tooling Guidance, this contribution was prepared with AI assistance. I have reviewed and verified every change.