Repository navigation
fix(compliance): check the dataset in an AGG(dataset.metric) argument against the model - #815
Conversation
… against the model The grader resolves a dataset qualifier against the authored model before it compares expression trees, but only for fields: _field_owners reads datasets[].fields. The argument of AGG(dataset.metric) names a dataset-scoped metric, which no dataset declares as a field, so its qualifier was dropped before the comparison. A return of AGG(orders.total_amount) for the authored AGG(sales.total_amount) graded as a cosmetic rewrite, where SUM(orders.amount) for SUM(sales.amount) needs review. AGG arguments are now resolved against the datasets that declare the metric (_metric_owners), with the same rules as fields: a qualifier that names another dataset needs review, a respelled or dropped qualifier is cosmetic when one dataset declares the metric, and it stays meaning when several do. Follow-up to the review of apache#758. Grader only, no fixture changes. Co-authored-by: Isaac <no-reply@databricks.com>
20dbc9c to
63620b1
Compare
| declarations = (metric_owners or {}) if agg_argument(column) else owners | ||
| declared_by = declarations.get(column.name.lower(), frozenset()) |
There was a problem hiding this comment.
When the name isn't a declared metric, or a caller doesn't pass metric_owners, the qualifier is dropped. Main still checked it against the field owners in that case: AGG(sales.amount) -> AGG(customers.amount) was review on main and is cosmetic here. No current caller hits this, but falling back keeps the grader from getting more lenient than main:
| declarations = (metric_owners or {}) if agg_argument(column) else owners | |
| declared_by = declarations.get(column.name.lower(), frozenset()) | |
| name = column.name.lower() | |
| declared_by = (metric_owners or {}).get(name, frozenset()) if agg_argument(column) else frozenset() | |
| declared_by = declared_by or owners.get(name, frozenset()) |
| # on M0 needs review. | ||
| finding = _m5_agg_finding("AGG(orders.total_amount) / NULLIF(AGG(orders.order_count), 0)") | ||
| assert finding.outcome == grade.REWRITTEN | ||
| assert finding.detail.startswith("review"), finding.detail |
There was a problem hiding this comment.
startswith("review") also matches "review: could not compare trees". If a parse failure happened, these tests would still pass without checking the qualifier resolution.
Could they assert finding.detail == "review: normalized trees differ"?
…at is not a metric An AGG argument no dataset declares as a metric, or one graded without metric_owners, lost its qualifier check. It is now checked against the fields, as on main. The review assertions of the AGG tests name the "normalized trees differ" detail, so a parse failure cannot pass them. Co-authored-by: Isaac <no-reply@databricks.com>
|
Thanks, both applied in b30dc20. The fallback is your suggestion as written, plus two tests for it (a name that is not a metric, and a caller without |
Summary
Follow-up to the review of #758.
The grader resolves a dataset qualifier against the authored model before it compares expression trees, so that
customers.amountreturned forsales.amountneeds review. It did that for fields only:_field_ownersreadsdatasets[].fields. The argument ofAGG(dataset.metric)names a dataset-scoped metric, which no dataset declares as a field, so its qualifier was dropped before the comparison:What changed:
_metric_ownersmaps each dataset-scoped metric name to the datasets that declare it, the counterpart of_field_owners.AGGis resolved against the metric owners, every other column against the field owners as before. The rules are the same as for fields: a qualifier that names another dataset needs review; a respelled or dropped qualifier is cosmetic when one dataset declares the metric; when several datasets declare it, the qualifier is meaning and dropping it needs review._dataset_aliasesrule) is still read as the authored dataset insideAGG.Out of scope: no fixture or manifest changes.
AGG(source.measure)in a dataset-scoped metric is unchanged; in that scope a written qualifier is already kept as written.Related Issues
Follow-up to #758 (review note on
m5_agg_ref.ossie.yaml).Validation
compliance/portability/grader: 64 passed (58 on main plus 6 new), with sqlglot 30.32.0, with the declared minimum 30.29.0, and with 25.0.0. The last one matters because older sqlglot parsesAGGas an anonymous function and newer versions as anAggnode; both paths are covered.grade.pyfour of the six new tests fail (the wrong dataset, the metric declared by two datasets, metric against field, and_metric_ownersitself). The two that pass there are the cosmetic cases, which must not change.M5.agg_refyet (its spec pin is older than test(compliance): add an M5 variant that composes through AGG(dataset.metric) #758), so no real return with anAGGcall was graded.pre-commitpasses on the three files.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 mergedocs/spec_changes.mdrecords rationale, compatibility and migration impact, or the PR explains why no entry is neededNo spec change: this is a grader fix under
compliance/portability/grader/.Tests
pytest/ CI green)Documentation
docs/is updated to reflect any user-facing changes (the grader README)Compliance