Repository navigation
docs(core-spec): Let dataset-scoped metrics reference source columns as source.column - #633
Conversation
42a0307 to
f403d0c
Compare
|
I welcome the Regarding column references. Are all columns always available? A dataset-scoped metric might be defined in terms of other metrics, and evaluated in a rolled-up context. As an analogy, consider the following SQL query: SELECT job, MAX(sal) - MIN(sal) + deptno AS m
FROM emp
GROUP BY jobThe reference to Would the This latter option I call "cube semantics", based on what comes out of the query SELECT job, deptno, MAX(sal) - MIN(sal) + deptno AS m
FROM emp
GROUP BY CUBE(job, deptno) |
|
Maybe we can talk more about "cube semantics" sometime. Once you're thinking in terms of SQL's |
…as source.column A dataset-scoped metric may now reference a column of its dataset's source, written as source.column. The source qualifier is case insensitive and reaches a column that a field of the same name shadows. Unqualified names must still be declared fields. source is not reserved. If a dataset declares a field named source, the field takes precedence, and the dataset's metrics cannot refer to source columns. The validator accepts source.column and reports its use in a dataset that declares a field named source. Co-authored-by: Isaac <no-reply@databricks.com>
f403d0c to
92a73f1
Compare
| qualifiers = set() | ||
| undeclared = set() | ||
| uses_source = False | ||
| for col in tree.find_all(exp.Column): |
There was a problem hiding this comment.
validate_metric_scoping rejects a dataset-scoped metric that uses DATEDIFF with a unit, because sqlglot parses the unit as a column. On 92a73f1, DATEDIFF(day, source.opened_at, source.closed_at) fails with "references undeclared field(s) 'day'". So does the form from expression_language.md, DATEDIFF(day, start_date, end_date), with both fields declared.
validate_metric_references and validate_field_shadowing already skip the unit through iter_columns. With it here, on 92a73f1 with sqlglot 30.27.0:
DATEDIFF(day, source.opened_at, source.closed_at)passes.DATEDIFF(day, start_date, end_date)with both fields declared passes.DATEDIFF(MINUTE, opened_at, CURRENT_TIMESTAMP)under OSSIE_SQL_2026 passes.DATEDIFF(day, opened_at, closed_at)withclosed_atundeclared reportsCLOSED_ATinstead ofday.SUM(minute)with no fieldminuteis still reported.validation/tests: 493 passed, the same as without the change.
| for col in tree.find_all(exp.Column): | |
| for col in iter_columns(tree): |
If you'd rather keep this PR's scope, I can send this as a follow-up after it lands, as I offered in #608.
There was a problem hiding this comment.
@ekut would you be able to address this as a followup once this PR lands?
There was a problem hiding this comment.
Happy to. It's #696, with tests for the forms in this thread and for COUNT(customers.*), which iter_columns would otherwise skip.
A dataset's metric may read a column of its source as source.column (apache/ossie#633). The qualifier is case insensitive, the column wins over a field of the same name, and a dataset that declares a field named source refuses the qualifier. validate --url checks the column, and a metric over a column the connected user cannot read is hidden. A call of AGG in any capitalization is refused in fields, metrics and filters, as the spec reserves the name (apache/ossie#662). ANSI_SQL entries are read by the same rule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A dataset's metric may read a column of its source as source.column (apache/ossie#633). The qualifier is case insensitive, the column wins over a field of the same name, and a dataset that declares a field named source refuses the qualifier. validate --url checks the column, and a metric over a column the connected user cannot read is hidden. A call of AGG in any capitalization is refused in fields, metrics and filters, as the spec reserves the name (apache/ossie#662). ANSI_SQL entries are read by the same rule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… audit (#711) * docs(spec-changes): correct and complete the 0.3.0.dev0 history Update the #577 and #591 rows, which later PRs superseded: #587 set the default NULL placement in window ORDER BY, and #633 lets dataset-scoped metrics reference source columns as source.column. State the #617 precedence of expression.sql as the MUST the spec makes it. Add the breaking changes merged in this window (#397 root dialects and vendors removed, #400 ontology uri renamed to iri, #486 name resolution), together with #587, #633 and the Layer 3 interface (#653). * fix(scripts): make the spec change audit see all of main Drop --first-parent: on a branch that has merged main, it followed the branch and skipped every main commit merged after the branch forked. Resolve the default history file and the pathspecs from the repository root, so running from a subdirectory no longer reports no candidates. Read --since as midnight UTC, matching the dates in the history, instead of the current local time on that date. Strip GIT_* variables and the user's git config from the test environment, so the tests cannot act on the developer's repository when run from a git hook, and run them in Validation CI.
apache/ossie#633 lets a dataset-scoped metric reference a column of its dataset's source as source.column. The qualifier is case insensitive. A field named source takes the name, and then the dataset's metrics cannot reach source columns. The converter already produced the right output for source.column, but only through the single-dataset fallback that accepts any qualifier. That fallback also accepted SUM(returns.amount) declared on orders and turned it into orders.amount. Dataset-scoped metrics now accept only source (when no field is named source) or the dataset's own name as a column qualifier. Anything else is dropped with UNSUPPORTED_METRIC_EXPRESSION. Model-level metrics keep the fallback.
…ension Address review from @kayemkim on PR apache#57: apache/ossie#633 landed source-column references for dataset-scoped metrics, so a source column that is not a declared field is now written source.column (e.g. SUM(source.quantity)) per Metric Scoping rule 1, not a future extension. Co-authored-by: Isaac <no-reply@databricks.com>
apache/ossie#633 lets a dataset-scoped metric reference a column of its dataset's source as source.column. The qualifier is case insensitive. A field named source takes the name, and then the dataset's metrics cannot reach source columns. The converter already produced the right output for source.column, but only through the single-dataset fallback that accepts any qualifier. That fallback also accepted SUM(returns.amount) declared on orders and turned it into orders.amount. Dataset-scoped metrics now accept only source (when no field is named source) or the dataset's own name as a column qualifier. Anything else is dropped with UNSUPPORTED_METRIC_EXPRESSION. Model-level metrics keep the fallback.
* docs: document dataset-scoped metrics in converter mapping guide Port the converter-guidance updates from apache/ossie#591 (dataset-scoped metrics) that were dropped when that PR merged. apache/ossie#523 had moved converters/ to apache/ossie-converters, so the converters/README.md edits in #591 were resolved as an accept-upstream-deletion and never landed here. The Mapping Core Constructs tables now list datasets[].metrics as a dataset-scoped placement alongside the model-root metrics, and the Metrics section describes the dataset-scoped vs model-scoped split and links to the Metric Scoping section of the core spec. Co-authored-by: Isaac <no-reply@databricks.com> * docs: dataset-scoped metric source columns are no longer a future extension Address review from @kayemkim on PR #57: apache/ossie#633 landed source-column references for dataset-scoped metrics, so a source column that is not a declared field is now written source.column (e.g. SUM(source.quantity)) per Metric Scoping rule 1, not a future extension. Co-authored-by: Isaac <no-reply@databricks.com> --------- Co-authored-by: Isaac <no-reply@databricks.com>
Summary
A dataset-scoped metric can now reference columns of its dataset's
source, written assource.column.Rules (
spec.mdMetric Scoping and Name Resolution,expression_language.mdName Spaces)SUM(net_amount).source:SUM(source.quantity). The qualifier is case insensitive.source.amountrefers to the source column even when the dataset declares a field namedamount.sourceis not reserved. If a dataset declares a field namedsource, the name refers to that field, and the dataset's metrics cannot refer to source columns.Changes from the earlier version of this PR, following JB's review:
source.is required for source columns. Unqualified source-column names are no longer accepted, so a reference can't silently change meaning when a field is added later. This could be relaxed in the future.Validator (
validation/validate.py)source.columnin dataset-scoped metrics.SUM(quantiy)fails.source.columnin a dataset that declares a field namedsource.spec.yaml,ossie-schema.json, and a comment in the Python model are updated to match.Related Issues
Follows #486 and #591.
AGG()reservation: #662 (was previously part of this PR, now moved out to its own PR).Checklist
Specification
core-spec/and follow the existing structureValidation
validation/are updated if the spec changedTests
validation/tests/: 493 passed;python/tests/: 268 passed)