Repository navigation
test(compliance): add portability rungs M4-M6 and the FILTER (WHERE) form of M3 - #631
Conversation
|
@kayemkim would you be able to approve the workflows and take a look when you have a moment? Happy to adjust anything. |
jbonofre
left a comment
There was a problem hiding this comment.
LGTM! Thanks @MrBlack1995!
I checked out the branch and ran the grader test and validate.py on the new and changed M3-M6 fixtures, including SQL validation, and all pass. I also graded the M4-M6 fixtures against themselves, and every finding comes back PORTABLE.
I see two potential follow-ups:
test_identity_on_real_m0_m3_fixtures_is_all_portableonly loops overm0-m3, so the new M4-M6 fixtures are not covered by the regression test. Please add"m4", "m5", "m6"to the loop and update the "M0-M3" wording ingrader/README.md.- M5 has
reference_form_primary: qualified, but its only variant isreference_form: metric-name. - M6's
element_under_testiskind: fields and metricwith a comma-joined name, so lookups by kind and name won't find it. Splitting it into separate elements, or picking one primary element, would fix that.
…t by kind and name Follow-ups from the review of apache#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>
|
Thanks a lot for checking it out and running everything! All three points are addressed:
While checking M5 against current main I found one more thing: since #608, One note for later, not for this PR: since #486 and #608, the bare variants of M0, M2 and M3 get "is not qualified" warnings, because a model-scoped metric must use |
|
@jbonofre thanks again for the review and for running the fixtures yourself, the follow-ups made the manifest a lot more useful. Pushing them dismissed your approval, so whenever you have a moment for another look: the changes are the two commits after 9e425fe, summarized in my comment above. Thanks! |
|
One more commit since my last note: 4baea94 drops |
|
Thanks @MrBlack1995! I'm doing a new pass 😄 |
| expression: | ||
| dialects: | ||
| - dialect: ANSI_SQL | ||
| expression: AVG(DATEDIFF('day', sales.order_date, sales.ship_date)) |
There was a problem hiding this comment.
The spec writes the date part as a bar keyword: DATEDIFF(day, start_date, end_date) (expression_language.md Date Functions).
DATEDIFF('day', ...) with quotes is the Tableau spelling in the Date Function Mapping table.
A converter that returns the spec form would be graded REWRITTEN ("normalized trees differ"), because sqlglot parses 'day' as a string literal and day as a column.
| expression: AVG(DATEDIFF('day', sales.order_date, sales.ship_date)) | |
| expression: AVG(DATEDIFF(day, sales.order_date, sales.ship_date)) |
DATE_TRUNC('month', order_date) is fine as it is, since the spec quotes the part there.
There was a problem hiding this comment.
Thanks, fixed in 008c947: AVG(DATEDIFF(day, sales.order_date, sales.ship_date)). DATE_TRUNC('month', ...) stays quoted, as the spec writes it.
| description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) | ||
| elements_under_test: | ||
| - kind: field | ||
| name: order_year |
There was a problem hiding this comment.
The grader keys fields as dataset.field, but the manifest names them bare: order_year and order_month_start here, and amount_with_tax in M1.
Anyone matching manifest elements to report.findings by (kind, name) won't find a result for any M1 or M6 field.
The new test doesn't catch this because _names in test_grade.py builds its own bare-name set instead of using the grader's keys.
Could we name fields the way the grader does (sales.order_year and so on) and have the test reuse _collect, so the two can't drift apart? For example:
def _names(document, kind):
return {name for (element_kind, name) in grade._collect(document) if element_kind == kind}There was a problem hiding this comment.
Done in 008c947: fields are named as the grader reports them (sales.amount_with_tax, sales.order_year, sales.order_month_start), and _names is now your version on top of grade._collect. Since the bare variants now hold dataset-scoped metrics (sales.total_amount in the grader), those four variants say metrics_in: sales, and the test expects <dataset>.<metric> for them. The test fails on the previous manifest; 18 grader tests pass.
…pelling in M6 Follow-ups from the second review of apache#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>
|
@MrBlack1995 I'm back on this one 😄 |
| expression: | ||
| dialects: | ||
| - dialect: ANSI_SQL | ||
| expression: SUM(sales.amount) / COUNT(DISTINCT customers.customer_id) |
There was a problem hiding this comment.
The grader can't tell this expression apart from the two ways a converter is most likely to break it.
_equivalent_tree drops every column table qualifier before comparing. Until now every rung had a single dataset, so that only erased spelling. Here customer_id is declared by both sales and customers, so the qualifier carries meaning. Against main grader, all three of these come back REEWRITTEN "cosmetic (normalized trees equal)":
SUM(sales.amount) / COUNT(DISTINCT customers.customer_id): as authored.SUM(sales.amount) / COUNT(DISTINCT sales.customer_id): join collapsed, now also counts customer ids with no customer row.SUM(amount) / COUNT(DISTINCT customer_id): unqualified, ambiguous at model scope (validate.pyonly warns).
interop/portability.py in ossie-converters counts a "cosmetic" REWRITTEN as portable. So a converter that loses the cross-dataset reference scores as portable on the rung that exists to measure it. _repair_by_expression has the same blind spot: a metric that is renamed and also re-pointed to sales.customer_id is paired as "expression equivalent".
To fix that, I suggest to keep the qualifier for any field name that more than one dataset in the input declares, and strip it as before otherwise. M0-M3 each have one dataset, so their grades don't change.
def _ambiguous_fields(document):
"""Field names declared by more than one dataset. For these the dataset
qualifier says which column is meant, so normalization must keep it."""
owners = {}
if isinstance(document, dict):
for dataset in document.get("datasets") or []:
if not isinstance(dataset, dict):
continue
for field_def in dataset.get("fields") or []:
if isinstance(field_def, dict) and field_def.get("name"):
owners.setdefault(str(field_def["name"]).lower(), set()).add(dataset.get("name"))
return frozenset(name for name, datasets in owners.items() if len(datasets) > 1)In _equivalent_tree(left, right, keep_qualified=frozenset()):
for column in tree.find_all(exp.Column):
if column.name.lower() in keep_qualified:
# Declared by more than one dataset: the qualifier is meaning.
continue
# Drop the table qualifier so sales.amount and amount compare equal.
column.set("table", None)then compute keep_qualified = _ambiguous_fields(input_document) once in grade() and pass it through _classify_present and _repair_by_expression to both _equivalent_tree calls. I ran this against main grader: the existing tests still pass, and the M4 cases come back as review.
There was a problem hiding this comment.
Thanks, good catch: M4 is the first rung where the qualifier carries meaning, and the grader erased it. Applied your approach in 3505677: _ambiguous_fields() reads the field names more than one input dataset declares, grade() computes it once and passes it through _classify_present and _repair_by_expression to both _equivalent_tree calls. M0-M3 grade as before (one dataset each). I also checked the converters side: interop/portability.py in ossie-converters#141 and the #65 runner both go through this grader and do no comparison of their own, so they pick the fix up with the next submodule bump.
Co-authored-by: Isaac <no-reply@databricks.com>
…ty grader The core grader compares normalized sqlglot trees, so a rewritten metric whose trees differ can only be marked for review. portability_execution.py runs the authored and the returned expression of each metric the grader marks REWRITTEN in DuckDB on the same small edge-case data and reports SAME_ON_TEST_DATA (evidence, not proof), DIFFERENT (with the smallest row set found and both results on it) or NOT_RUN (with the reason). The grader is loaded from the pinned ossie submodule. check() takes the grader's report for the round trip when the caller already has one, so a portability step and this check read the same findings; a single pair can also be checked with python -m interop.portability_execution. It is report-only: exit 0 whatever the findings, 2 when a document or the grader cannot be loaded. DuckDB runs in memory with external access and extension loading off and its configuration locked. Division by zero is NULL (ieee_floating_point_ops = false, plus error_on_division_by_zero = false on DuckDB 2, which otherwise raises), so a rewrite that only adds a NULLIF guard agrees, as discussed on apache#24. Tests set the M3 ELSE 0 form themselves rather than reading it from the fixture, which apache/ossie#631 changes. Refs apache#24.
3505677 to
ae3efae
Compare
…t by kind and name Follow-ups from the review of apache#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>
…pelling in M6 Follow-ups from the second review of apache#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>
|
Rebased onto main after #642 merged: the conflicts in |
…ters#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>
…eclare 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>
main moved the in-development version to 0.3.0.dev0 (apache#691), and the schema pins it, so the fixtures this PR adds declare it too. Co-authored-by: Isaac <no-reply@databricks.com>
… declares the field Review of apache#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>
282fe83 to
d2c4643
Compare
|
Rebased onto main (now d2c4643): #729, #730 and #732 changed the same grader functions over the weekend, so this PR had conflicts. The resolution keeps both sides: their |
…ty grader The core grader compares normalized sqlglot trees, so a rewritten metric whose trees differ can only be marked for review. portability_execution.py runs the authored and the returned expression of each metric the grader marks REWRITTEN in DuckDB on the same small edge-case data and reports SAME_ON_TEST_DATA (evidence, not proof), DIFFERENT (with the smallest row set found and both results on it) or NOT_RUN (with the reason). The grader is loaded from the pinned ossie submodule. check() takes the grader's report for the round trip when the caller already has one, so a portability step and this check read the same findings; a single pair can also be checked with python -m interop.portability_execution. It is report-only: exit 0 whatever the findings, 2 when a document or the grader cannot be loaded. DuckDB runs in memory with external access and extension loading off and its configuration locked. Division by zero is NULL (ieee_floating_point_ops = false, plus error_on_division_by_zero = false on DuckDB 2, which otherwise raises), so a rewrite that only adds a NULLIF guard agrees, as discussed on apache#24. Tests set the M3 ELSE 0 form themselves rather than reading it from the fixture, which apache/ossie#631 changes. Refs apache#24.
kayemkim
left a comment
There was a problem hiding this comment.
The rebase leaves the grading as it was at 282fe83: every variant I ran then comes back the same on d2c4643 merged with current main. The sql rule from #729 and #730 also holds on the M4 qualifier cases. A requalified sql is cosmetic, one that names the other dataset needs review, and an ANSI_SQL entry that survives does not cover for a sql that changed.
| if home: | ||
| return column.table.lower() if column.table else home | ||
| declared_by = owners.get(column.name.lower(), frozenset()) | ||
| if not declared_by: | ||
| return None # no dataset declares it, so there is nothing to check against | ||
| if column.table: | ||
| return column.table.lower() |
There was a problem hiding this comment.
A returned qualifier is now kept as written, so when a converter renames a dataset, every metric and field that names it is graded as dropped.
Lightdash names a dataset after its source table. For M0.ansi.qualified it returns a dataset orders (source: samples.sales.orders) and orders_total_amount = SUM(orders.amount) for the authored dataset sales and total_amount = SUM(sales.amount). Main pairs the two as "identity not preserved" (the review column). With this change orders stays orders, the trees differ, and total_amount is graded DROPPED_SILENT, plus an unrelated ADDED orders_total_amount.
The M1 field gets the same treatment (amount * 1.1 comes back as orders.amount * 1.1).
I graded all 120 portability cases from the latest Interop matrix run on apache/ossie-converters main with main's grader and with this one. 19 lightdash elements in 8 cases (M0 x3, M1, M2 x2, M3 x2) move from review to DROPPED_SILENT, and nothing else changes. The converters table would then show lightdash silently dropping metrics it actually returned.
I suggest when a returned dataset has the same source as an authored one, treat it as that dataset, and map its qualifiers on the returned side before resolving. I tried this locally. The 120 CI cases then grade exactly as on main, and all 43 tests here still pass, including test_a_field_qualified_by_another_dataset_needs_review.
Could we add a test built from lightdash's real M0 return, so this can't regress?
There was a problem hiding this comment.
Fixed in 0995481 as you suggested: a returned dataset that reads the source of exactly one authored dataset is treated as that dataset, and its qualifiers are mapped on the returned side before resolving. The 120 CI cases now grade as on main, and test_a_dataset_renamed_after_its_source_is_the_authored_dataset is built from lightdash's real M0 return. Details in the comment below.
| # M5 ladder rung: metric composition. A metric expression cannot refer to other | ||
| # metrics (core-spec/spec.md, Metric Scoping; expression_language.md), so a | ||
| # composed measure in a source tool (avg_order_value = total_amount / order_count) | ||
| # is carried with its parts inlined: a ratio of two aggregates over qualified | ||
| # dataset.field references, NULL when there are no orders. The two base metrics | ||
| # stay alongside it. Single fixture. |
There was a problem hiding this comment.
Since #703 this premise no longer holds. A model-scoped metric may now evaluate a dataset-scoped metric with AGG(dataset.metric) (core-spec/spec.md, Metric Scoping rule 6, expression_language.md, the AGG section). This commit predates #703, so it was right when you wrote it.
The fixture is still valid, and inlining is still a legitimate way to carry composition. But the rung should not say it is the only way. Could we reword this comment, the construct in manifest.yaml and the M5 row in the README to say the composition is carried inlined, without claiming that metrics cannot reference metrics?
A follow-up variant that composes AGG(sales.total_amount) / AGG(sales.order_count) over dataset-scoped base metrics would test real composition. That doesn't need to block this PR.
There was a problem hiding this comment.
Reworded in 639958b: the fixture comment, the manifest construct and the README row now say the composition is carried inlined, and that AGG(dataset.metric) is not tested by this rung. Glad to add the AGG variant as a follow-up.
…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>
…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>
|
Thanks @jbonofre, both are fixed. Renamed datasets (0995481), along the lines you suggested: I graded the 120 portability cases of the latest Interop matrix run on ossie-converters main (run 44032883483) with main's grader, with d2c4643 and with this commit. At d2c4643 I get what you found: 19 lightdash elements in 8 cases move to DROPPED_SILENT, each with an unrelated ADDED. With the fix, all 120 cases grade exactly as on main. New tests: M5 (639958b): the fixture comment, the manifest construct and the README row now say the composition is carried inlined, and that composition through |
kayemkim
left a comment
There was a problem hiding this comment.
The alias only moves a qualifier onto the dataset that reads the same source, so the M4 check still holds through a rename. With both datasets renamed, SUM(cust.amount) for an authored SUM(sales.amount) still needs review, and so does a return that swaps the two names. My earlier variants grade the same as before.
jbonofre
left a comment
There was a problem hiding this comment.
LGTM! Thanks @MrBlack1995!
I graded the 120 portability cases from the latest Interop matrix run on apache/ossie-converters main, with main's grader and with this one, and every finding is the same. I also ran the 14 graded converters locally on the new fixtures (the M3 FILTER variants, M4-M6, and the bare variants as dataset-scoped metrics), with the converters' pinned submodule and the PR's compliance/portability. The grades look right, except for one M6 issue that the grader already has on main.
|
Thanks for running all 14 converters on the new rungs. Which M6 issue do you mean? If it's a grader gap, I'm happy to take it as a follow-up once this lands. |
Since apache/ossie#631 the grader keys a metric declared under datasets[].metrics as dataset.metric. _find_metric now looks such a name up under that dataset's metrics, and a bare name in a dataset-scoped metric resolves to its home dataset, as the spec reads it, even when another dataset declares a field of the same name. Point 2 of the apache#127 review.
…ty grader (#127) * test(interop): add a report-only execution check behind the portability grader The core grader compares normalized sqlglot trees, so a rewritten metric whose trees differ can only be marked for review. portability_execution.py runs the authored and the returned expression of each metric the grader marks REWRITTEN in DuckDB on the same small edge-case data and reports SAME_ON_TEST_DATA (evidence, not proof), DIFFERENT (with the smallest row set found and both results on it) or NOT_RUN (with the reason). The grader is loaded from the pinned ossie submodule. check() takes the grader's report for the round trip when the caller already has one, so a portability step and this check read the same findings; a single pair can also be checked with python -m interop.portability_execution. It is report-only: exit 0 whatever the findings, 2 when a document or the grader cannot be loaded. DuckDB runs in memory with external access and extension loading off and its configuration locked. Division by zero is NULL (ieee_floating_point_ops = false, plus error_on_division_by_zero = false on DuckDB 2, which otherwise raises), so a rewrite that only adds a NULLIF guard agrees, as discussed on #24. Tests set the M3 ELSE 0 form themselves rather than reading it from the fixture, which apache/ossie#631 changes. Refs #24. * feat(interop): run the execution check in Runner.portability_case As described in #141, Runner.portability_case now calls portability_execution.check(input_document, returned_document, converter=..., graded=report) right after grader.grade(...) and stores the result as `execution` next to `grading`, so both read the same findings. It is saved in the case's result.json and in results.json. A skipped case is not executed (`execution` stays None), and a rejected return has nothing to execute. Without DuckDB each check is NOT_RUN with the reason. Report-only: the exit status is unchanged, with or without --strict. portability_execution.grader() now loads the grader through interop.portability.load_grader, so the runner and the check share one grader module. as_dict() gives the JSON-ready report the runner stores. Refs #24, #141. * fix(interop): follow-ups from the #127 review - Take "cosmetic" from the grader's own finding instead of comparing the trees again, so the check cannot skip a pair the grader, with more context, marks for review. - Read the portable `sql` form as OSSIE_SQL_2026, shadowing an OSSIE_SQL_2026 dialect entry, the way the grader reads it (apache/ossie#642). - Move DuckDB into an optional `execution` dependency group; CI installs it. Without it every execution finding stays NOT_RUN. * fix(interop): find dataset-scoped metrics in the execution check Since apache/ossie#631 the grader keys a metric declared under datasets[].metrics as dataset.metric. _find_metric now looks such a name up under that dataset's metrics, and a bare name in a dataset-scoped metric resolves to its home dataset, as the spec reads it, even when another dataset declares a field of the same name. Point 2 of the #127 review.
apache/ossie#631 adds the M6 rung (YEAR, DATE_TRUNC, DATEDIFF). It shows two converter gaps: the round trip upper-cases the DATE_TRUNC unit, which the grader scores as REWRITTEN, and `translate` has no verified DATABRICKS form for DATEDIFF. Both rung tests are strict xfails until the converter handles them. The M0 qualified OSSIE_SQL case now passes against the sql-primary grader, as its comment anticipated, so its xfail goes. Co-authored-by: Isaac <no-reply@databricks.com>
…ble_extensions (#247) * chore(deps): bump ossie from `ee89dbd` to `344259a` Co-authored-by: Isaac <no-reply@databricks.com> * test(databricks): expect the M6 ladder rung to fail, drop the M0 xfail apache/ossie#631 adds the M6 rung (YEAR, DATE_TRUNC, DATEDIFF). It shows two converter gaps: the round trip upper-cases the DATE_TRUNC unit, which the grader scores as REWRITTEN, and `translate` has no verified DATABRICKS form for DATEDIFF. Both rung tests are strict xfails until the converter handles them. The M0 qualified OSSIE_SQL case now passes against the sql-primary grader, as its comment anticipated, so its xfail goes. Co-authored-by: Isaac <no-reply@databricks.com> * test(interop): stop pairing the bare and qualified ladder fixtures by name The submodule's bare M0-M3 fixtures now carry their metrics at dataset scope, so they no longer name the same metrics as the model-scoped qualified fixtures. The tests derive the bare form from the qualified fixture instead, as the module already does for any metric whose shape it depends on. The grader rejects only a missing or empty return since apache/ossie#757, so the rejection test passes `{}`, which is what the matrix passes when an export fails. Co-authored-by: Isaac <no-reply@databricks.com> * fix(converters): write nonportable_extensions with object data apache/ossie#522 renames `custom_extensions` to `nonportable_extensions` with no alias, and types `data` as an object instead of a JSON string. The SDK renames `OssieCustomExtension` to `OssieNonportableExtension` and types `data` as `dict`. Every converter now writes and reads the new field with object data. Where a payload may hold values JSON cannot (dates from a YAML loader), it still goes through the converter's existing JSON encoding, now decoded back to an object. Committed fixtures and goldens move to the new shape. Vendor-side formats keep their own shapes: OBML `customExtensions` data stays a string, and Honeydew's `ossie` metadata keeps its item names. thoughtspot keeps reading both names and both shapes, and keeps a document that still uses the old name on it. orionbelt's v0.1 shim migrates a legacy `custom_extensions` list before it reads it. Tests that built a malformed JSON string cannot be constructed against the SDK any more and are removed, along with lightdash's EXTENSION_DATA_INVALID issue, which can no longer occur. Co-authored-by: Isaac <no-reply@databricks.com> * fix(databricks): translate DATEDIFF by day and keep the M6 rung portable The M6 ladder rung (YEAR, DATE_TRUNC, DATEDIFF) did not survive a round trip, for three reasons: - The default parser reads Ossie's part-first DATEDIFF(day, start, end) end-first, with the part as a column. The Ossie parser now reads the part first. Only the day count is translated: the Ossie specification does not say whether DATEDIFF counts part boundaries or whole parts elapsed (Databricks), and the two agree only for the days between two dates. - sqlglot upper-cases the DATE_TRUNC unit, so DATE_TRUNC('month', d) came back as 'MONTH'. Ossie output now writes the unit in lower case, as the specification does. - The Databricks parser wraps the argument of YEAR, MONTH, DAY and DAYOFYEAR in a TO_DATE that was not written. The wrapper is dropped on parse, so YEAR(x) comes back as YEAR(x). The M6 xfails go, as does the M0 xfail that expected the sql-primary grader. Co-authored-by: Isaac <no-reply@databricks.com> * test(dbt): move the ratio helper tests to nonportable_extensions Co-authored-by: Isaac <no-reply@databricks.com> * fix(atlan, wisdom): write nonportable_extensions with object data Co-authored-by: Isaac <no-reply@databricks.com> --------- Co-authored-by: Isaac <no-reply@databricks.com>
Summary
Follow-up to #596: the next portability rungs, one commit each, on top of the M0-M3 set. Each rung still adds one construct, so a difference in a converter's output localizes to it. Happy to drop or split any of these.
FILTER (WHERE ...)clause, whichexpression_language.mdmakes REQUIRED, qualified and bare. The existingCASEfixtures now omitELSE 0(SUM(CASE WHEN ... THEN amount END)), so both forms are the same aggregate, as the spec's note underFILTER (WHERE ...)states; withELSE 0they gave 0 whereFILTERgives NULL (found by @idk-arsh's execution check on apache/ossie-converters#24)m3/m3_filter_clause_qualified.ossie.yaml,m3/m3_filter_clause_bare.ossie.yamlm4/m4_cross_dataset.ossie.yamlSUM(sales.amount) / NULLIF(COUNT(sales.order_id), 0)), since a metric expression cannot refer to other metrics (Metric Scoping incore-spec/spec.md)m5/m5_metric_ref.ossie.yamlYEAR,DATE_TRUNC, part-firstDATEDIFF(part, start, end)m6/m6_date_scalars.ossie.yamlmanifest.yamlgets one entry per rung (and the two M3 variants), and the README table lists M0-M6. Each rung lists itselements_under_testwith one kind (metric or field) and the name the grader reports it under (a field asdataset.field); a variant whose metrics are dataset-scoped says so withmetrics_in: sales.Bare variants (M0, M2, M3) are dataset-scoped metrics now. Since #486 a model-scoped metric must qualify
dataset.field, so the bare form moves todatasets[].metrics, where the single-part name is the required form. The grader read only the model-rootmetricsand skipped dataset-scoped ones entirely (and the identity test still passed), so it now collectsdatasets[].metricsas well, keyeddataset.metricas the spec references them; the identity test asserts every metric in a fixture is graded. M6 writesDATEDIFF(day, ...), the spec's spelling.M7 and M8 (window and offset functions) are not included: they wait for the default NULL placement in window
ORDER BY(#587).Validation
validation/validate.pyon current main with no warnings (including the reference checks from feat(validation): check metric references and field shadowing against Name Resolution #608)._collect) in each variant, and that each primary variant uses the rung's primary reference form. Three tests cover a dataset-scoped metric graded PORTABLE, dropped, and moved to the model root (REWRITTEN).Related Issues
Refs apache/ossie-converters#24 (portability measurement). Follows #596.