From f9b11628961d7c4d42595c8b4618ab4b7f88bd35 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Thu, 22 Oct 2026 17:13:51 +0200 Subject: [PATCH 01/11] 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 --- .../portability/m6/m6_date_scalars.ossie.yaml | 59 +++++++++++++++++++ compliance/portability/manifest.yaml | 10 ++++ 2 files changed, 69 insertions(+) create mode 100644 compliance/portability/m6/m6_date_scalars.ossie.yaml diff --git a/compliance/portability/m6/m6_date_scalars.ossie.yaml b/compliance/portability/m6/m6_date_scalars.ossie.yaml new file mode 100644 index 000000000..50e73736e --- /dev/null +++ b/compliance/portability/m6/m6_date_scalars.ossie.yaml @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# M6 ladder rung: date and time scalars from the portable core (YEAR, +# DATE_TRUNC, DATEDIFF). DATEDIFF uses the spec's part-first argument order +# DATEDIFF(part, start, end). The date-part fields resolve inside their own +# dataset (sibling columns), and the DATEDIFF metric uses the qualified form. +version: "0.2.0.dev0" +name: m6_sales +description: "M6: date and time scalar functions from the portable core." +datasets: + - name: sales + source: samples.sales.orders + fields: + - name: order_date + expression: + dialects: + - dialect: ANSI_SQL + expression: order_date + datatype: Date + - name: ship_date + expression: + dialects: + - dialect: ANSI_SQL + expression: ship_date + datatype: Date + - name: order_year + expression: + dialects: + - dialect: ANSI_SQL + expression: YEAR(order_date) + datatype: Integer + - name: order_month_start + expression: + dialects: + - dialect: ANSI_SQL + expression: DATE_TRUNC('month', order_date) + datatype: Date +metrics: + - name: avg_fulfillment_days + expression: + dialects: + - dialect: ANSI_SQL + expression: AVG(DATEDIFF('day', sales.order_date, sales.ship_date)) + datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 0382f779f..21a9cd350 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -103,3 +103,13 @@ rungs: variants: - {id: M3.filtered_agg.qualified, file: m3/m3_filtered_agg_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - {id: M3.filtered_agg.bare, file: m3/m3_filtered_agg_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} + + - id: M6 + description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) + element_under_test: + kind: fields and metric + name: order_year, order_month_start, avg_fulfillment_days + construct: date scalar functions (DATEDIFF(part, start, end) per expression_language.md) + reference_form_primary: qualified # the fields reference sibling columns intra-dataset + variants: + - {id: M6.date_scalars, file: m6/m6_date_scalars.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} From 102d2d83c8cff0e356e6e8151624a9b19b84cdc6 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Thu, 22 Oct 2026 17:14:20 +0200 Subject: [PATCH 02/11] 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 --- .../m3/m3_filter_clause_bare.ossie.yaml | 47 +++++++++++++++++++ .../m3/m3_filter_clause_qualified.ossie.yaml | 47 +++++++++++++++++++ compliance/portability/manifest.yaml | 4 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 compliance/portability/m3/m3_filter_clause_bare.ossie.yaml create mode 100644 compliance/portability/m3/m3_filter_clause_qualified.ossie.yaml diff --git a/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml b/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml new file mode 100644 index 000000000..795743af6 --- /dev/null +++ b/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# M3 ladder rung, filter-clause form: the same filtered aggregate as the CASE +# WHEN fixtures, written with the aggregate FILTER (WHERE ...) clause that +# expression_language.md makes REQUIRED. Comparing the two forms shows whether a +# converter handles the clause itself. Variant: BARE reference form, kept as a sibling variant. +version: "0.2.0.dev0" +name: m3_sales +description: "M3: conditional aggregation with the FILTER (WHERE ...) clause, bare reference form." +datasets: + - name: sales + source: samples.sales.orders + fields: + - name: amount + expression: + dialects: + - dialect: ANSI_SQL + expression: amount + datatype: Decimal + - name: status + expression: + dialects: + - dialect: ANSI_SQL + expression: status + datatype: String +metrics: + - name: completed_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(amount) FILTER (WHERE status = 'completed') + datatype: Decimal diff --git a/compliance/portability/m3/m3_filter_clause_qualified.ossie.yaml b/compliance/portability/m3/m3_filter_clause_qualified.ossie.yaml new file mode 100644 index 000000000..49af6d340 --- /dev/null +++ b/compliance/portability/m3/m3_filter_clause_qualified.ossie.yaml @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# M3 ladder rung, filter-clause form: the same filtered aggregate as the CASE +# WHEN fixtures, written with the aggregate FILTER (WHERE ...) clause that +# expression_language.md makes REQUIRED. Comparing the two forms shows whether a +# converter handles the clause itself. Variant: QUALIFIED reference form, carried as primary. +version: "0.2.0.dev0" +name: m3_sales +description: "M3: conditional aggregation with the FILTER (WHERE ...) clause, qualified reference form." +datasets: + - name: sales + source: samples.sales.orders + fields: + - name: amount + expression: + dialects: + - dialect: ANSI_SQL + expression: amount + datatype: Decimal + - name: status + expression: + dialects: + - dialect: ANSI_SQL + expression: status + datatype: String +metrics: + - name: completed_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(sales.amount) FILTER (WHERE sales.status = 'completed') + datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 21a9cd350..965b0cd0d 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -94,7 +94,7 @@ rungs: - {id: M2.aggregates.bare, file: m2/m2_aggregates_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} - id: M3 - description: a filtered aggregate in the portable form SUM(CASE WHEN ... THEN x ELSE 0 END) + description: a filtered aggregate, in the portable form SUM(CASE WHEN ... THEN x ELSE 0 END) and with the REQUIRED FILTER (WHERE ...) clause element_under_test: kind: metric name: completed_amount @@ -103,6 +103,8 @@ rungs: variants: - {id: M3.filtered_agg.qualified, file: m3/m3_filtered_agg_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - {id: M3.filtered_agg.bare, file: m3/m3_filtered_agg_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} + - {id: M3.filter_clause.qualified, file: m3/m3_filter_clause_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: filter-clause-form} + - {id: M3.filter_clause.bare, file: m3/m3_filter_clause_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: filter-clause-form} - id: M6 description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) From bc64a5c529e91f7e4c621545a7bc9ce98495c21f Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Thu, 22 Oct 2026 17:14:42 +0200 Subject: [PATCH 03/11] 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 --- .../m4/m4_cross_dataset.ossie.yaml | 63 +++++++++++++++++++ compliance/portability/manifest.yaml | 10 +++ 2 files changed, 73 insertions(+) create mode 100644 compliance/portability/m4/m4_cross_dataset.ossie.yaml diff --git a/compliance/portability/m4/m4_cross_dataset.ossie.yaml b/compliance/portability/m4/m4_cross_dataset.ossie.yaml new file mode 100644 index 000000000..768eb7901 --- /dev/null +++ b/compliance/portability/m4/m4_cross_dataset.ossie.yaml @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# M4 ladder rung: two datasets and a relationship, with a metric that +# aggregates across the join. A cross-dataset metric must qualify its columns +# by dataset to be unambiguous, so this rung has a single qualified fixture +# (no bare variant: a bare column would not say which dataset it belongs to). +version: "0.2.0.dev0" +name: m4_sales +description: "M4: two datasets, a relationship, and a cross-dataset metric." +datasets: + - name: sales + source: samples.sales.orders + fields: + - name: amount + expression: + dialects: + - dialect: ANSI_SQL + expression: amount + datatype: Decimal + - name: customer_id + expression: + dialects: + - dialect: ANSI_SQL + expression: customer_id + datatype: Integer + - name: customers + source: samples.sales.customers + primary_key: [customer_id] + fields: + - name: customer_id + expression: + dialects: + - dialect: ANSI_SQL + expression: customer_id + datatype: Integer +relationships: + - name: sales_to_customer + from: sales + to: customers + from_columns: [customer_id] + to_columns: [customer_id] +metrics: + - name: revenue_per_customer + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(sales.amount) / COUNT(DISTINCT customers.customer_id) + datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 965b0cd0d..dad7a0836 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -115,3 +115,13 @@ rungs: reference_form_primary: qualified # the fields reference sibling columns intra-dataset variants: - {id: M6.date_scalars, file: m6/m6_date_scalars.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} + + - id: M4 + description: two datasets joined by a relationship, with a model-scoped metric across the join + element_under_test: + kind: metric + name: revenue_per_customer + construct: cross-dataset (model-scoped) metric over a declared relationship + reference_form_primary: qualified # model-scoped metrics reference dataset.field + variants: + - {id: M4.cross_dataset, file: m4/m4_cross_dataset.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} From 44587329b3e2fd81c9e4c459b3d4f81c848ea861 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Thu, 22 Oct 2026 17:15:07 +0200 Subject: [PATCH 04/11] 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 --- .../portability/m5/m5_metric_ref.ossie.yaml | 59 +++++++++++++++++++ compliance/portability/manifest.yaml | 10 ++++ 2 files changed, 69 insertions(+) create mode 100644 compliance/portability/m5/m5_metric_ref.ossie.yaml diff --git a/compliance/portability/m5/m5_metric_ref.ossie.yaml b/compliance/portability/m5/m5_metric_ref.ossie.yaml new file mode 100644 index 000000000..29eda689d --- /dev/null +++ b/compliance/portability/m5/m5_metric_ref.ossie.yaml @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# M5 ladder rung: metric composition, a model-scoped metric that references +# other model-scoped metrics by name (avg_order_value refers to total_amount and +# order_count), as described under Metric Scoping in core-spec/spec.md, where a +# model-scoped metric is referenced as metric_name. Single fixture. +version: "0.2.0.dev0" +name: m5_sales +description: "M5: a metric that references other metrics (composition)." +datasets: + - name: sales + source: samples.sales.orders + fields: + - name: amount + expression: + dialects: + - dialect: ANSI_SQL + expression: amount + datatype: Decimal + - name: order_id + expression: + dialects: + - dialect: ANSI_SQL + expression: order_id + datatype: Integer +metrics: + - name: total_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(sales.amount) + datatype: Decimal + - name: order_count + expression: + dialects: + - dialect: ANSI_SQL + expression: COUNT(sales.order_id) + datatype: Integer + - name: avg_order_value + expression: + dialects: + - dialect: ANSI_SQL + expression: total_amount / order_count + datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index dad7a0836..a4965ecc2 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -125,3 +125,13 @@ rungs: reference_form_primary: qualified # model-scoped metrics reference dataset.field variants: - {id: M4.cross_dataset, file: m4/m4_cross_dataset.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} + + - id: M5 + description: a model-scoped metric composed from other model-scoped metrics, referenced by name + element_under_test: + kind: metric + name: avg_order_value + construct: metric-to-metric reference (total_amount / order_count) + reference_form_primary: qualified # base metrics qualify dataset.field; the composite references metric names + variants: + - {id: M5.metric_ref, file: m5/m5_metric_ref.ossie.yaml, tag: ANSI_SQL, reference_form: metric-name, role: primary} From 9e425fef60190b468cbbf24d5d7633754c7dc423 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Thu, 22 Oct 2026 17:15:42 +0200 Subject: [PATCH 05/11] 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 --- compliance/portability/README.md | 19 +++++++++++-------- compliance/portability/manifest.yaml | 25 ++++++++++++------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/compliance/portability/README.md b/compliance/portability/README.md index 9039231ac..7a87927f0 100644 --- a/compliance/portability/README.md +++ b/compliance/portability/README.md @@ -17,7 +17,7 @@ under the License. --> -# Portability measurement ladder (M0-M3) +# Portability measurement ladder (M0-M6) A small set of portable fixtures, and a grader, for measuring how faithfully a model survives a round-trip through each converter. This is issue #576 @@ -37,7 +37,10 @@ difference in a converter's output localizes to a single construct: | M0 | baseline | one dataset, one field, one `SUM` metric | | M1 | a scalar field, no aggregation | `amount * 1.1` calculated column | | M2 | the core aggregate set | `SUM`, `COUNT`, `COUNT(DISTINCT)`, `AVG`, `MIN`, `MAX` | -| M3 | a filtered aggregate | `SUM(CASE WHEN ... THEN x ELSE 0 END)` | +| M3 | a filtered aggregate | `SUM(CASE WHEN ... THEN x ELSE 0 END)`, and the same with `FILTER (WHERE ...)` | +| M4 | a cross-dataset metric | two datasets, a relationship, a model-scoped metric across the join | +| M5 | metric composition | a model-scoped metric built from two other metrics by name | +| M6 | date and time scalars | `YEAR`, `DATE_TRUNC`, `DATEDIFF(part, start, end)` | `manifest.yaml` lists the fixtures, the element each rung exercises, and the per-element outcome vocabulary the grader assigns (PORTABLE / TAG_PRESERVED, @@ -61,10 +64,10 @@ grades the real fixtures all-PORTABLE. See `grader/README.md`. ## Scope and placement -Rungs M4-M8 (relationships and cross-dataset metrics, metric-to-metric -composition, date and time scalars, window and offset functions) are held -pending #354, #591 and #587, and are not in this set. +Rungs M7 and M8 (window and offset functions: time intelligence and +ratio-to-total) are held until the default NULL placement in window `ORDER BY` +is settled (#587), and are not in this set. -Location is a starting point. If these should sit with the interoperability -harness from #348 or elsewhere once that lands, they can move; the fixtures are -self-contained and the manifest paths are relative. +The fixtures measure the specification rather than any one converter, so they +live in this repository; the fixtures are self-contained and the manifest paths +are relative. diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index a4965ecc2..3d8cd12b0 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -35,9 +35,8 @@ # expression, so it carries a single fixture. # # All fixtures validate.py-pass on apache/ossie main (9531429) with sqlglot -# 29.0.1. Rungs M4-M8 (relationships, metric composition, date scalars, window -# and offset functions) are held pending #354, #591 and #587; they are not in -# this set. +# 29.0.1. Rungs M7 and M8 (window and offset functions) are held pending #587; +# they are not in this set. outcomes: # per-element, assigned by the grader after diffing input vs returned output @@ -106,16 +105,6 @@ rungs: - {id: M3.filter_clause.qualified, file: m3/m3_filter_clause_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: filter-clause-form} - {id: M3.filter_clause.bare, file: m3/m3_filter_clause_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: filter-clause-form} - - id: M6 - description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) - element_under_test: - kind: fields and metric - name: order_year, order_month_start, avg_fulfillment_days - construct: date scalar functions (DATEDIFF(part, start, end) per expression_language.md) - reference_form_primary: qualified # the fields reference sibling columns intra-dataset - variants: - - {id: M6.date_scalars, file: m6/m6_date_scalars.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - - id: M4 description: two datasets joined by a relationship, with a model-scoped metric across the join element_under_test: @@ -135,3 +124,13 @@ rungs: reference_form_primary: qualified # base metrics qualify dataset.field; the composite references metric names variants: - {id: M5.metric_ref, file: m5/m5_metric_ref.ossie.yaml, tag: ANSI_SQL, reference_form: metric-name, role: primary} + + - id: M6 + description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) + element_under_test: + kind: fields and metric + name: order_year, order_month_start, avg_fulfillment_days + construct: date scalar functions (DATEDIFF(part, start, end) per expression_language.md) + reference_form_primary: qualified # the fields reference sibling columns intra-dataset + variants: + - {id: M6.date_scalars, file: m6/m6_date_scalars.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} From adb53bb3d732eef8b81fe5bc90012189990cbc25 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Fri, 30 Oct 2026 06:45:07 +0100 Subject: [PATCH 06/11] 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 --- compliance/portability/grader/README.md | 6 +- compliance/portability/grader/test_grade.py | 54 ++++++++++++-- compliance/portability/manifest.yaml | 83 +++++++++++++-------- 3 files changed, 105 insertions(+), 38 deletions(-) diff --git a/compliance/portability/grader/README.md b/compliance/portability/grader/README.md index 0f699de97..cbd3351f9 100644 --- a/compliance/portability/grader/README.md +++ b/compliance/portability/grader/README.md @@ -62,5 +62,7 @@ PLACEHOLDER, ADDED, RELABELED, DROPPED_DIAGNOSED, DROPPED_SILENT, REJECTED. ## Tests `test_grade.py` has one test per outcome plus an identity check that runs the real -M0-M3 fixtures through a no-op converter and asserts every element grades -PORTABLE. Run with `PYTHONPATH=. pytest test_grade.py`. +M0-M6 fixtures through a no-op converter and asserts every element grades +PORTABLE. Two manifest checks assert that every element the manifest names is found +by kind and name in each variant, and that each primary variant uses the rung's primary +reference form. Run with `PYTHONPATH=. pytest test_grade.py`. diff --git a/compliance/portability/grader/test_grade.py b/compliance/portability/grader/test_grade.py index 1b35bb84f..445f92c1c 100644 --- a/compliance/portability/grader/test_grade.py +++ b/compliance/portability/grader/test_grade.py @@ -18,8 +18,11 @@ """Outcome tests for the #576 fidelity grader. Each test builds a tiny input document and a synthetic returned document that -exercises exactly one outcome. The last test runs the real posted M0-M3 fixtures +exercises exactly one outcome. The identity test runs the real posted M0-M6 fixtures through a no-op converter: returned unchanged, every element must grade PORTABLE. +The manifest tests check that every element the manifest names can be found by +kind and name in each variant, and that each primary variant uses the rung's +primary reference form. """ import glob @@ -27,6 +30,8 @@ import grade +HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + def _metric(name, dialect, expression): return {"name": name, "expression": {"dialects": [{"dialect": dialect, "expression": expression}]}} @@ -144,16 +149,53 @@ def test_whitespace_is_not_a_difference(): assert _only(grade.grade(src, returned)).outcome == grade.PORTABLE -def test_identity_on_real_m0_m3_fixtures_is_all_portable(): - here = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +def test_identity_on_real_m0_m6_fixtures_is_all_portable(): files = sorted( path - for rung in ("m0", "m1", "m2", "m3") - for path in glob.glob(os.path.join(here, rung, "*.ossie.yaml")) + for rung in ("m0", "m1", "m2", "m3", "m4", "m5", "m6") + for path in glob.glob(os.path.join(HERE, rung, "*.ossie.yaml")) ) - assert files, "no M0-M3 fixtures found" + assert files, "no M0-M6 fixtures found" for path in files: document = grade._load(path) report = grade.grade(document, document) bad = [(f.name, f.outcome) for f in report.findings if f.outcome != grade.PORTABLE] assert not bad, f"{os.path.basename(path)} graded non-PORTABLE: {bad}" + + +def _manifest_rungs(): + return grade._load(os.path.join(HERE, "manifest.yaml"))["rungs"] + + +def _names(document, kind): + if kind == "metric": + return {metric["name"] for metric in document.get("metrics") or []} + return { + field["name"] + for dataset in document.get("datasets") or [] + for field in dataset.get("fields") or [] + } + + +def test_every_manifest_element_is_found_by_kind_and_name_in_each_variant(): + checked = 0 + for rung in _manifest_rungs(): + for variant in rung["variants"]: + document = grade._load(os.path.join(HERE, variant["file"])) + for element in rung["elements_under_test"]: + assert element["kind"] in ("metric", "field"), (rung["id"], element) + assert element["name"] in _names(document, element["kind"]), ( + variant["id"], + element, + ) + checked += 1 + assert checked, "the manifest names no elements" + + +def test_each_primary_variant_uses_the_rungs_primary_reference_form(): + for rung in _manifest_rungs(): + if rung["reference_form_primary"] == "n/a": + continue + primary = [v for v in rung["variants"] if v["role"] == "primary"] + assert len(primary) == 1, rung["id"] + assert primary[0]["reference_form"] == rung["reference_form_primary"], rung["id"] diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 3d8cd12b0..9c0465903 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -23,7 +23,8 @@ # through every converter; a vendor-tagged input would only exercise one # converter, which is not what a cross-converter measurement wants. # -# This manifest lists the fixtures and the single element each rung exercises. +# This manifest lists the fixtures and the elements each rung exercises, each by +# kind (metric or field) and name, as they appear in every variant of the rung. # It does NOT encode per-converter expected outputs: those are measured by a # grader that diffs the returned document against the input element by element # into the outcome vocabulary below. Conformance stays a floor (validate.py @@ -62,10 +63,10 @@ outcomes: rungs: - id: M0 description: one dataset, one field, one SUM metric - element_under_test: - kind: metric - name: total_amount - construct: single-column aggregate (SUM) + elements_under_test: + - kind: metric + name: total_amount + construct: single-column aggregate (SUM) reference_form_primary: qualified variants: - {id: M0.ansi.qualified, file: m0/m0_ansi_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} @@ -74,19 +75,35 @@ rungs: - id: M1 description: baseline plus one scalar calculated-column field expression, no aggregation - element_under_test: - kind: field - name: amount_with_tax - construct: scalar field expression (amount * 1.1) + elements_under_test: + - kind: field + name: amount_with_tax + construct: scalar field expression (amount * 1.1) reference_form_primary: n/a # intra-dataset field expression references its sibling column bare variants: - {id: M1.scalar_field, file: m1/m1_scalar_field.ossie.yaml, tag: ANSI_SQL, reference_form: intra-dataset, role: primary} - id: M2 description: the core aggregate set (SUM, COUNT, COUNT DISTINCT, AVG, MIN, MAX) - element_under_test: - kind: metrics - construct: core aggregate set + elements_under_test: + - kind: metric + name: sum_amount + construct: SUM + - kind: metric + name: count_orders + construct: COUNT + - kind: metric + name: distinct_customers + construct: COUNT DISTINCT + - kind: metric + name: avg_amount + construct: AVG + - kind: metric + name: min_amount + construct: MIN + - kind: metric + name: max_amount + construct: MAX reference_form_primary: qualified variants: - {id: M2.aggregates.qualified, file: m2/m2_aggregates_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} @@ -94,10 +111,10 @@ rungs: - id: M3 description: a filtered aggregate, in the portable form SUM(CASE WHEN ... THEN x ELSE 0 END) and with the REQUIRED FILTER (WHERE ...) clause - element_under_test: - kind: metric - name: completed_amount - construct: conditional aggregation + elements_under_test: + - kind: metric + name: completed_amount + construct: conditional aggregation reference_form_primary: qualified variants: - {id: M3.filtered_agg.qualified, file: m3/m3_filtered_agg_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} @@ -107,30 +124,36 @@ rungs: - id: M4 description: two datasets joined by a relationship, with a model-scoped metric across the join - element_under_test: - kind: metric - name: revenue_per_customer - construct: cross-dataset (model-scoped) metric over a declared relationship + elements_under_test: + - kind: metric + name: revenue_per_customer + construct: cross-dataset (model-scoped) metric over a declared relationship reference_form_primary: qualified # model-scoped metrics reference dataset.field variants: - {id: M4.cross_dataset, file: m4/m4_cross_dataset.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - id: M5 description: a model-scoped metric composed from other model-scoped metrics, referenced by name - element_under_test: - kind: metric - name: avg_order_value - construct: metric-to-metric reference (total_amount / order_count) - reference_form_primary: qualified # base metrics qualify dataset.field; the composite references metric names + elements_under_test: + - kind: metric + name: avg_order_value + construct: metric-to-metric reference (total_amount / order_count) + reference_form_primary: metric-name # the composite under test references metric names (its base metrics qualify dataset.field) variants: - {id: M5.metric_ref, file: m5/m5_metric_ref.ossie.yaml, tag: ANSI_SQL, reference_form: metric-name, role: primary} - id: M6 description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) - element_under_test: - kind: fields and metric - name: order_year, order_month_start, avg_fulfillment_days - construct: date scalar functions (DATEDIFF(part, start, end) per expression_language.md) - reference_form_primary: qualified # the fields reference sibling columns intra-dataset + elements_under_test: + - kind: field + name: order_year + construct: YEAR + - kind: field + name: order_month_start + construct: DATE_TRUNC + - kind: metric + name: avg_fulfillment_days + construct: DATEDIFF(part, start, end) per expression_language.md + reference_form_primary: qualified # the metric qualifies dataset.field; the fields reference sibling columns bare (intra-dataset) variants: - {id: M6.date_scalars, file: m6/m6_date_scalars.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} From 69f9c368968b43324b2a39ea887f810f767652c4 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Fri, 30 Oct 2026 06:48:50 +0100 Subject: [PATCH 07/11] 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 --- compliance/portability/README.md | 2 +- compliance/portability/m5/m5_metric_ref.ossie.yaml | 14 ++++++++------ compliance/portability/manifest.yaml | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/compliance/portability/README.md b/compliance/portability/README.md index 7a87927f0..dce66f612 100644 --- a/compliance/portability/README.md +++ b/compliance/portability/README.md @@ -39,7 +39,7 @@ difference in a converter's output localizes to a single construct: | M2 | the core aggregate set | `SUM`, `COUNT`, `COUNT(DISTINCT)`, `AVG`, `MIN`, `MAX` | | M3 | a filtered aggregate | `SUM(CASE WHEN ... THEN x ELSE 0 END)`, and the same with `FILTER (WHERE ...)` | | M4 | a cross-dataset metric | two datasets, a relationship, a model-scoped metric across the join | -| M5 | metric composition | a model-scoped metric built from two other metrics by name | +| M5 | metric composition | a model-scoped metric built from two others, inlined (a metric expression cannot refer to other metrics) | | M6 | date and time scalars | `YEAR`, `DATE_TRUNC`, `DATEDIFF(part, start, end)` | `manifest.yaml` lists the fixtures, the element each rung exercises, and the diff --git a/compliance/portability/m5/m5_metric_ref.ossie.yaml b/compliance/portability/m5/m5_metric_ref.ossie.yaml index 29eda689d..030624c33 100644 --- a/compliance/portability/m5/m5_metric_ref.ossie.yaml +++ b/compliance/portability/m5/m5_metric_ref.ossie.yaml @@ -15,13 +15,15 @@ # specific language governing permissions and limitations # under the License. -# M5 ladder rung: metric composition, a model-scoped metric that references -# other model-scoped metrics by name (avg_order_value refers to total_amount and -# order_count), as described under Metric Scoping in core-spec/spec.md, where a -# model-scoped metric is referenced as metric_name. Single fixture. +# 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. version: "0.2.0.dev0" name: m5_sales -description: "M5: a metric that references other metrics (composition)." +description: "M5: a composed metric, with the metrics it is built from inlined." datasets: - name: sales source: samples.sales.orders @@ -55,5 +57,5 @@ metrics: expression: dialects: - dialect: ANSI_SQL - expression: total_amount / order_count + expression: SUM(sales.amount) / NULLIF(COUNT(sales.order_id), 0) datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 9c0465903..0a0d09b75 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -133,14 +133,14 @@ rungs: - {id: M4.cross_dataset, file: m4/m4_cross_dataset.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - id: M5 - description: a model-scoped metric composed from other model-scoped metrics, referenced by name + description: a model-scoped metric composed from two others, with their expressions inlined elements_under_test: - kind: metric name: avg_order_value - construct: metric-to-metric reference (total_amount / order_count) - reference_form_primary: metric-name # the composite under test references metric names (its base metrics qualify dataset.field) + construct: composition inlined (total_amount / order_count as SUM(...) / NULLIF(COUNT(...), 0)); metric expressions cannot refer to other metrics + reference_form_primary: qualified variants: - - {id: M5.metric_ref, file: m5/m5_metric_ref.ossie.yaml, tag: ANSI_SQL, reference_form: metric-name, role: primary} + - {id: M5.metric_ref, file: m5/m5_metric_ref.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - id: M6 description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) From 4baea949b9e5e09cf4eb0bea6581c3d3909cb1ab Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Sun, 1 Nov 2026 07:24:53 +0100 Subject: [PATCH 08/11] 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 --- compliance/portability/README.md | 2 +- compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml | 6 ++++-- .../portability/m3/m3_filtered_agg_qualified.ossie.yaml | 6 ++++-- compliance/portability/manifest.yaml | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compliance/portability/README.md b/compliance/portability/README.md index dce66f612..c8a8f4c99 100644 --- a/compliance/portability/README.md +++ b/compliance/portability/README.md @@ -37,7 +37,7 @@ difference in a converter's output localizes to a single construct: | M0 | baseline | one dataset, one field, one `SUM` metric | | M1 | a scalar field, no aggregation | `amount * 1.1` calculated column | | M2 | the core aggregate set | `SUM`, `COUNT`, `COUNT(DISTINCT)`, `AVG`, `MIN`, `MAX` | -| M3 | a filtered aggregate | `SUM(CASE WHEN ... THEN x ELSE 0 END)`, and the same with `FILTER (WHERE ...)` | +| M3 | a filtered aggregate | `SUM(CASE WHEN ... THEN x END)` (no `ELSE`, so it equals the `FILTER` form), and the same with `FILTER (WHERE ...)` | | M4 | a cross-dataset metric | two datasets, a relationship, a model-scoped metric across the join | | M5 | metric composition | a model-scoped metric built from two others, inlined (a metric expression cannot refer to other metrics) | | M6 | date and time scalars | `YEAR`, `DATE_TRUNC`, `DATEDIFF(part, start, end)` | diff --git a/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml b/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml index 244483381..72da00b0a 100644 --- a/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml +++ b/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml @@ -16,7 +16,9 @@ # under the License. # M3 ladder rung: a filtered aggregate in the spec's portable form -# SUM(CASE WHEN ... THEN x ELSE 0 END). Variant: BARE reference form, kept as a +# SUM(CASE WHEN ... THEN x END), with no ELSE: a non-matching row contributes +# NULL, so the result equals the FILTER (WHERE ...) form (expression_language.md, +# Conditional Aggregations; an ELSE 0 would count as a real row). Variant: BARE reference form, kept as a # sibling variant pending #343. version: "0.2.0.dev0" name: m3_sales @@ -42,5 +44,5 @@ metrics: expression: dialects: - dialect: ANSI_SQL - expression: SUM(CASE WHEN status = 'completed' THEN amount ELSE 0 END) + expression: SUM(CASE WHEN status = 'completed' THEN amount END) datatype: Decimal diff --git a/compliance/portability/m3/m3_filtered_agg_qualified.ossie.yaml b/compliance/portability/m3/m3_filtered_agg_qualified.ossie.yaml index 0edaa573b..8553ce85d 100644 --- a/compliance/portability/m3/m3_filtered_agg_qualified.ossie.yaml +++ b/compliance/portability/m3/m3_filtered_agg_qualified.ossie.yaml @@ -16,7 +16,9 @@ # under the License. # M3 ladder rung: a filtered aggregate in the spec's portable form -# SUM(CASE WHEN ... THEN x ELSE 0 END). Variant: QUALIFIED reference form, +# SUM(CASE WHEN ... THEN x END), with no ELSE: a non-matching row contributes +# NULL, so the result equals the FILTER (WHERE ...) form (expression_language.md, +# Conditional Aggregations; an ELSE 0 would count as a real row). Variant: QUALIFIED reference form, # carried as primary per #486. version: "0.2.0.dev0" name: m3_sales @@ -42,5 +44,5 @@ metrics: expression: dialects: - dialect: ANSI_SQL - expression: SUM(CASE WHEN sales.status = 'completed' THEN sales.amount ELSE 0 END) + expression: SUM(CASE WHEN sales.status = 'completed' THEN sales.amount END) datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 0a0d09b75..978e4bd5d 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -110,7 +110,7 @@ rungs: - {id: M2.aggregates.bare, file: m2/m2_aggregates_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} - id: M3 - description: a filtered aggregate, in the portable form SUM(CASE WHEN ... THEN x ELSE 0 END) and with the REQUIRED FILTER (WHERE ...) clause + description: a filtered aggregate, in the portable form SUM(CASE WHEN ... THEN x END) (no ELSE, equal to FILTER per expression_language.md) and with the REQUIRED FILTER (WHERE ...) clause elements_under_test: - kind: metric name: completed_amount From f0ae6ca920cfd4fe1234b5f384f65e690499ca75 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Fri, 30 Oct 2026 07:02:16 +0100 Subject: [PATCH 09/11] 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 --- compliance/portability/grader/README.md | 5 ++ compliance/portability/grader/grade.py | 11 ++- compliance/portability/grader/test_grade.py | 54 ++++++++++++- .../portability/m0/m0_sum_bare.ossie.yaml | 26 +++--- .../m2/m2_aggregates_bare.ossie.yaml | 81 ++++++++++--------- .../m3/m3_filter_clause_bare.ossie.yaml | 20 +++-- .../m3/m3_filtered_agg_bare.ossie.yaml | 21 ++--- compliance/portability/manifest.yaml | 9 ++- 8 files changed, 151 insertions(+), 76 deletions(-) diff --git a/compliance/portability/grader/README.md b/compliance/portability/grader/README.md index cbd3351f9..020bb87b7 100644 --- a/compliance/portability/grader/README.md +++ b/compliance/portability/grader/README.md @@ -29,6 +29,11 @@ in `../manifest.yaml`. A thin runner (modelled on `cube/tools/interop_matrix.py` apache/ossie-converters) drives each converter and feeds the grader, so the measurement table becomes one command. +Elements are metrics and field expressions. A model-scoped metric is keyed by its +name, a dataset-scoped metric (`datasets[].metrics`) and a field by `dataset.name`, +the way the spec references them. A metric a converter moves between the two scopes +with the same expression is graded REWRITTEN (identity not preserved), not PORTABLE. + ## Usage ``` diff --git a/compliance/portability/grader/grade.py b/compliance/portability/grader/grade.py index 7d8cd34a0..6b5f56f44 100644 --- a/compliance/portability/grader/grade.py +++ b/compliance/portability/grader/grade.py @@ -157,7 +157,12 @@ class Element: def _collect(document): - """Collect metrics and field expressions, keyed by (kind, name).""" + """Collect metrics and field expressions, keyed by (kind, name). + + A dataset-scoped metric (``datasets[].metrics``) is keyed ``dataset.metric``, + the name the spec references it by, so it cannot collide with a model-scoped + metric of the same name. + """ elements = {} if not isinstance(document, dict): return elements @@ -173,6 +178,10 @@ def _collect(document): if isinstance(field_def, dict) and field_def.get("name"): name = f"{dataset_name}.{field_def['name']}" elements[("field", name)] = Element("field", name, _dialect_map(field_def.get("expression"))) + for metric in dataset.get("metrics") or []: + if isinstance(metric, dict) and metric.get("name"): + name = f"{dataset_name}.{metric['name']}" + elements[("metric", name)] = Element("metric", name, _dialect_map(metric.get("expression"))) return elements diff --git a/compliance/portability/grader/test_grade.py b/compliance/portability/grader/test_grade.py index 445f92c1c..5da92ed6e 100644 --- a/compliance/portability/grader/test_grade.py +++ b/compliance/portability/grader/test_grade.py @@ -22,7 +22,8 @@ through a no-op converter: returned unchanged, every element must grade PORTABLE. The manifest tests check that every element the manifest names can be found by kind and name in each variant, and that each primary variant uses the rung's -primary reference form. +primary reference form. The dataset-scoped tests check that a metric in +``datasets[].metrics`` is graded as ``dataset.metric``. """ import glob @@ -161,6 +162,10 @@ def test_identity_on_real_m0_m6_fixtures_is_all_portable(): report = grade.grade(document, document) bad = [(f.name, f.outcome) for f in report.findings if f.outcome != grade.PORTABLE] assert not bad, f"{os.path.basename(path)} graded non-PORTABLE: {bad}" + graded = sum(1 for f in report.findings if f.kind == "metric") + assert graded == len(_names(document, "metric")), ( + f"{os.path.basename(path)}: not every metric was graded" + ) def _manifest_rungs(): @@ -169,7 +174,11 @@ def _manifest_rungs(): def _names(document, kind): if kind == "metric": - return {metric["name"] for metric in document.get("metrics") or []} + return {metric["name"] for metric in document.get("metrics") or []} | { + metric["name"] + for dataset in document.get("datasets") or [] + for metric in dataset.get("metrics") or [] + } return { field["name"] for dataset in document.get("datasets") or [] @@ -199,3 +208,44 @@ def test_each_primary_variant_uses_the_rungs_primary_reference_form(): primary = [v for v in rung["variants"] if v["role"] == "primary"] assert len(primary) == 1, rung["id"] assert primary[0]["reference_form"] == rung["reference_form_primary"], rung["id"] + + +def _dataset_metric_document(metric_expression="SUM(amount)"): + return { + "datasets": [ + { + "name": "sales", + "fields": [{"name": "amount", "expression": {"dialects": [ + {"dialect": "ANSI_SQL", "expression": "amount"}]}}], + "metrics": [_metric("total_amount", "ANSI_SQL", metric_expression)], + } + ] + } + + +def test_a_dataset_scoped_metric_is_graded_under_dataset_dot_name(): + document = _dataset_metric_document() + report = grade.grade(document, document) + outcomes = {(f.kind, f.name): f.outcome for f in report.findings} + assert outcomes[("metric", "sales.total_amount")] == grade.PORTABLE + + +def test_a_dropped_dataset_scoped_metric_is_reported(): + returned = _dataset_metric_document() + returned["datasets"][0]["metrics"] = [] + report = grade.grade(_dataset_metric_document(), returned) + outcomes = {(f.kind, f.name): f.outcome for f in report.findings} + assert outcomes[("metric", "sales.total_amount")] == grade.DROPPED_SILENT + + +def test_a_dataset_scoped_metric_moved_to_the_model_is_not_the_same_element(): + returned = _dataset_metric_document() + returned["datasets"][0]["metrics"] = [] + returned["metrics"] = [_metric("total_amount", "ANSI_SQL", "SUM(amount)")] + report = grade.grade(_dataset_metric_document(), returned) + outcomes = {(f.kind, f.name): f.outcome for f in report.findings} + # Same expression under another name: one element whose identity changed, + # not a drop plus an unrelated addition. + assert outcomes[("metric", "sales.total_amount")] == grade.REWRITTEN + assert ("metric", "total_amount") not in outcomes + diff --git a/compliance/portability/m0/m0_sum_bare.ossie.yaml b/compliance/portability/m0/m0_sum_bare.ossie.yaml index aac63ba18..579de1ab1 100644 --- a/compliance/portability/m0/m0_sum_bare.ossie.yaml +++ b/compliance/portability/m0/m0_sum_bare.ossie.yaml @@ -18,13 +18,11 @@ # yaml-language-server: $schema=../../../../core-spec/ossie-schema.json # # M0 ladder rung -- one dataset, one field, one SUM metric. -# Variant: BARE reference form -- SUM(amount), a bare column name rather than -# dataset.field. ANSI_SQL tag. This is the "SUM(amount)" variant from the runs. -# Kept as a sibling variant to the qualified primary, not baked into the rung, -# because #343 (bare name means a source column inside a dataset-scoped metric) -# and #486 (qualified dataset.field only) are still settling which form is the -# model-level reference. sigma drops this as a cross-dataset metric on a -# one-dataset model. +# Variant: BARE reference form, carried as a DATASET-SCOPED metric +# (datasets[].metrics), where core-spec/spec.md (Metric Scoping) requires the +# single-part field name. A bare name in a model-scoped metric is not valid +# since #486; the qualified primary keeps the model-scoped form. +# ANSI_SQL tag. This is the "SUM(amount)" variant from the runs. version: "0.2.0.dev0" name: m0_sales description: M0 baseline -- single dataset, single field, single SUM metric. @@ -38,10 +36,10 @@ datasets: - dialect: ANSI_SQL expression: amount datatype: Decimal -metrics: - - name: total_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: SUM(amount) - datatype: Decimal + metrics: + - name: total_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(amount) + datatype: Decimal diff --git a/compliance/portability/m2/m2_aggregates_bare.ossie.yaml b/compliance/portability/m2/m2_aggregates_bare.ossie.yaml index bf5ca36c3..861b9259d 100644 --- a/compliance/portability/m2/m2_aggregates_bare.ossie.yaml +++ b/compliance/portability/m2/m2_aggregates_bare.ossie.yaml @@ -15,8 +15,11 @@ # specific language governing permissions and limitations # under the License. -# M2 ladder rung: the core aggregate set as metrics. Variant: BARE reference -# form (column name only), kept as a sibling variant pending #343. +# M2 ladder rung: the core aggregate set as metrics. +# Variant: BARE reference form, carried as a DATASET-SCOPED metric +# (datasets[].metrics), where core-spec/spec.md (Metric Scoping) requires the +# single-part field name. A bare name in a model-scoped metric is not valid +# since #486; the qualified primary keeps the model-scoped form. version: "0.2.0.dev0" name: m2_sales description: "M2: core aggregate set, bare reference form." @@ -42,40 +45,40 @@ datasets: - dialect: ANSI_SQL expression: customer_id datatype: Integer -metrics: - - name: sum_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: SUM(amount) - datatype: Decimal - - name: count_orders - expression: - dialects: - - dialect: ANSI_SQL - expression: COUNT(order_id) - datatype: Integer - - name: distinct_customers - expression: - dialects: - - dialect: ANSI_SQL - expression: COUNT(DISTINCT customer_id) - datatype: Integer - - name: avg_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: AVG(amount) - datatype: Decimal - - name: min_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: MIN(amount) - datatype: Decimal - - name: max_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: MAX(amount) - datatype: Decimal + metrics: + - name: sum_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(amount) + datatype: Decimal + - name: count_orders + expression: + dialects: + - dialect: ANSI_SQL + expression: COUNT(order_id) + datatype: Integer + - name: distinct_customers + expression: + dialects: + - dialect: ANSI_SQL + expression: COUNT(DISTINCT customer_id) + datatype: Integer + - name: avg_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: AVG(amount) + datatype: Decimal + - name: min_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: MIN(amount) + datatype: Decimal + - name: max_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: MAX(amount) + datatype: Decimal diff --git a/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml b/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml index 795743af6..25c34536f 100644 --- a/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml +++ b/compliance/portability/m3/m3_filter_clause_bare.ossie.yaml @@ -18,7 +18,11 @@ # M3 ladder rung, filter-clause form: the same filtered aggregate as the CASE # WHEN fixtures, written with the aggregate FILTER (WHERE ...) clause that # expression_language.md makes REQUIRED. Comparing the two forms shows whether a -# converter handles the clause itself. Variant: BARE reference form, kept as a sibling variant. +# converter handles the clause itself. +# Variant: BARE reference form, carried as a DATASET-SCOPED metric +# (datasets[].metrics), where core-spec/spec.md (Metric Scoping) requires the +# single-part field name. A bare name in a model-scoped metric is not valid +# since #486; the qualified primary keeps the model-scoped form. version: "0.2.0.dev0" name: m3_sales description: "M3: conditional aggregation with the FILTER (WHERE ...) clause, bare reference form." @@ -38,10 +42,10 @@ datasets: - dialect: ANSI_SQL expression: status datatype: String -metrics: - - name: completed_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: SUM(amount) FILTER (WHERE status = 'completed') - datatype: Decimal + metrics: + - name: completed_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(amount) FILTER (WHERE status = 'completed') + datatype: Decimal diff --git a/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml b/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml index 72da00b0a..1286b68c0 100644 --- a/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml +++ b/compliance/portability/m3/m3_filtered_agg_bare.ossie.yaml @@ -18,8 +18,11 @@ # M3 ladder rung: a filtered aggregate in the spec's portable form # SUM(CASE WHEN ... THEN x END), with no ELSE: a non-matching row contributes # NULL, so the result equals the FILTER (WHERE ...) form (expression_language.md, -# Conditional Aggregations; an ELSE 0 would count as a real row). Variant: BARE reference form, kept as a -# sibling variant pending #343. +# Conditional Aggregations; an ELSE 0 would count as a real row). +# Variant: BARE reference form, carried as a DATASET-SCOPED metric +# (datasets[].metrics), where core-spec/spec.md (Metric Scoping) requires the +# single-part field name. A bare name in a model-scoped metric is not valid +# since #486; the qualified primary keeps the model-scoped form. version: "0.2.0.dev0" name: m3_sales description: "M3: conditional aggregation, bare reference form." @@ -39,10 +42,10 @@ datasets: - dialect: ANSI_SQL expression: status datatype: String -metrics: - - name: completed_amount - expression: - dialects: - - dialect: ANSI_SQL - expression: SUM(CASE WHEN status = 'completed' THEN amount END) - datatype: Decimal + metrics: + - name: completed_amount + expression: + dialects: + - dialect: ANSI_SQL + expression: SUM(CASE WHEN status = 'completed' THEN amount END) + datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 978e4bd5d..8ac45085e 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -31,9 +31,12 @@ # passing); scoring stays a harness job (see #348). # # Reference form: the qualified dataset.field form is carried as the primary -# fixture wherever a metric references a dataset field, with the bare form as a -# sibling variant, pending #486 and #343. M1's element is an intra-dataset field -# expression, so it carries a single fixture. +# fixture wherever a metric references a dataset field, as a model-scoped metric. +# The bare form is a sibling variant carried as a dataset-scoped metric +# (datasets[].metrics), the only place the spec allows a single-part field name +# in a metric (Metric Scoping, #486). The grader keys a dataset-scoped metric as +# dataset.metric. M1's element is an intra-dataset field expression, so it +# carries a single fixture. # # All fixtures validate.py-pass on apache/ossie main (9531429) with sqlglot # 29.0.1. Rungs M7 and M8 (window and offset functions) are held pending #587; From 008c947c4514a2ebed810012019ac83c6b9698c0 Mon Sep 17 00:00:00 2001 From: "Mr. Black 1995" Date: Mon, 2 Nov 2026 07:22:16 +0100 Subject: [PATCH 10/11] 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., 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.). 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 --- compliance/portability/grader/test_grade.py | 21 ++++++++----------- .../portability/m6/m6_date_scalars.ossie.yaml | 2 +- compliance/portability/manifest.yaml | 19 ++++++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/compliance/portability/grader/test_grade.py b/compliance/portability/grader/test_grade.py index 5da92ed6e..dd674e65d 100644 --- a/compliance/portability/grader/test_grade.py +++ b/compliance/portability/grader/test_grade.py @@ -173,17 +173,14 @@ def _manifest_rungs(): def _names(document, kind): - if kind == "metric": - return {metric["name"] for metric in document.get("metrics") or []} | { - metric["name"] - for dataset in document.get("datasets") or [] - for metric in dataset.get("metrics") or [] - } - return { - field["name"] - for dataset in document.get("datasets") or [] - for field in dataset.get("fields") or [] - } + # The grader's own keys, so the manifest and the findings cannot drift apart. + return {name for (element_kind, name) in grade._collect(document) if element_kind == kind} + + +def _reported_name(element, variant): + if element["kind"] == "metric" and variant.get("metrics_in"): + return f"{variant['metrics_in']}.{element['name']}" + return element["name"] def test_every_manifest_element_is_found_by_kind_and_name_in_each_variant(): @@ -193,7 +190,7 @@ def test_every_manifest_element_is_found_by_kind_and_name_in_each_variant(): document = grade._load(os.path.join(HERE, variant["file"])) for element in rung["elements_under_test"]: assert element["kind"] in ("metric", "field"), (rung["id"], element) - assert element["name"] in _names(document, element["kind"]), ( + assert _reported_name(element, variant) in _names(document, element["kind"]), ( variant["id"], element, ) diff --git a/compliance/portability/m6/m6_date_scalars.ossie.yaml b/compliance/portability/m6/m6_date_scalars.ossie.yaml index 50e73736e..8e160493c 100644 --- a/compliance/portability/m6/m6_date_scalars.ossie.yaml +++ b/compliance/portability/m6/m6_date_scalars.ossie.yaml @@ -55,5 +55,5 @@ metrics: expression: dialects: - dialect: ANSI_SQL - expression: AVG(DATEDIFF('day', sales.order_date, sales.ship_date)) + expression: AVG(DATEDIFF(day, sales.order_date, sales.ship_date)) datatype: Decimal diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index 8ac45085e..dd37d3b1c 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -24,7 +24,10 @@ # converter, which is not what a cross-converter measurement wants. # # This manifest lists the fixtures and the elements each rung exercises, each by -# kind (metric or field) and name, as they appear in every variant of the rung. +# kind (metric or field) and by the name the grader reports it under: a field as +# dataset.field, a model-scoped metric by its name. A variant with +# `metrics_in: ` carries the rung's metrics as dataset-scoped metrics of +# that dataset, which the grader reports as .. # It does NOT encode per-converter expected outputs: those are measured by a # grader that diffs the returned document against the input element by element # into the outcome vocabulary below. Conformance stays a floor (validate.py @@ -74,13 +77,13 @@ rungs: variants: - {id: M0.ansi.qualified, file: m0/m0_ansi_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - {id: M0.ossiesql.qualified, file: m0/m0_ossiesql_qualified.ossie.yaml, tag: OSSIE_SQL_2026, reference_form: qualified, role: tag-sensitivity} - - {id: M0.sum.bare, file: m0/m0_sum_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} + - {id: M0.sum.bare, file: m0/m0_sum_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant, metrics_in: sales} - id: M1 description: baseline plus one scalar calculated-column field expression, no aggregation elements_under_test: - kind: field - name: amount_with_tax + name: sales.amount_with_tax construct: scalar field expression (amount * 1.1) reference_form_primary: n/a # intra-dataset field expression references its sibling column bare variants: @@ -110,7 +113,7 @@ rungs: reference_form_primary: qualified variants: - {id: M2.aggregates.qualified, file: m2/m2_aggregates_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - - {id: M2.aggregates.bare, file: m2/m2_aggregates_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} + - {id: M2.aggregates.bare, file: m2/m2_aggregates_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant, metrics_in: sales} - id: M3 description: a filtered aggregate, in the portable form SUM(CASE WHEN ... THEN x END) (no ELSE, equal to FILTER per expression_language.md) and with the REQUIRED FILTER (WHERE ...) clause @@ -121,9 +124,9 @@ rungs: reference_form_primary: qualified variants: - {id: M3.filtered_agg.qualified, file: m3/m3_filtered_agg_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} - - {id: M3.filtered_agg.bare, file: m3/m3_filtered_agg_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant} + - {id: M3.filtered_agg.bare, file: m3/m3_filtered_agg_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: reference-form-variant, metrics_in: sales} - {id: M3.filter_clause.qualified, file: m3/m3_filter_clause_qualified.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: filter-clause-form} - - {id: M3.filter_clause.bare, file: m3/m3_filter_clause_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: filter-clause-form} + - {id: M3.filter_clause.bare, file: m3/m3_filter_clause_bare.ossie.yaml, tag: ANSI_SQL, reference_form: bare, role: filter-clause-form, metrics_in: sales} - id: M4 description: two datasets joined by a relationship, with a model-scoped metric across the join @@ -149,10 +152,10 @@ rungs: description: date and time scalars from the portable core (YEAR, DATE_TRUNC, DATEDIFF part-first) elements_under_test: - kind: field - name: order_year + name: sales.order_year construct: YEAR - kind: field - name: order_month_start + name: sales.order_month_start construct: DATE_TRUNC - kind: metric name: avg_fulfillment_days From e3c38a89fad654c4c1a89f161849db13929b91fb Mon Sep 17 00:00:00 2001 From: Mario de Felipe Date: Tue, 3 Nov 2026 19:28:24 +0100 Subject: [PATCH 11/11] test(compliance): add S1 rung carrying SAP source-defined sentinel rules (#401) Four recognition rules (initial key, blank-as-state, initial DATS before CAST, open-ended validity marker) and one metric that excludes the sentinel from a populated count, authored as portable ANSI_SQL expressions over a customer-sales-area shaped dataset. The rung measures whether the rule survives a round trip; the spec has no construct to declare the sentinel itself. Targets the elements_under_test manifest shape from #631. Co-Authored-By: Claude Fable 5.1 --- compliance/portability/README.md | 7 ++ compliance/portability/grader/test_grade.py | 8 +- compliance/portability/manifest.yaml | 22 ++++ .../s1/s1_sentinel_rules.ossie.yaml | 100 ++++++++++++++++++ 4 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 compliance/portability/s1/s1_sentinel_rules.ossie.yaml diff --git a/compliance/portability/README.md b/compliance/portability/README.md index c8a8f4c99..d110f973f 100644 --- a/compliance/portability/README.md +++ b/compliance/portability/README.md @@ -41,6 +41,7 @@ difference in a converter's output localizes to a single construct: | M4 | a cross-dataset metric | two datasets, a relationship, a model-scoped metric across the join | | M5 | metric composition | a model-scoped metric built from two others, inlined (a metric expression cannot refer to other metrics) | | M6 | date and time scalars | `YEAR`, `DATE_TRUNC`, `DATEDIFF(part, start, end)` | +| S1 | source-defined sentinel rules | `CASE WHEN x = '' THEN NULL ...` for SAP-style initial values (#401): the rule is graded, the sentinel is not declared | `manifest.yaml` lists the fixtures, the element each rung exercises, and the per-element outcome vocabulary the grader assigns (PORTABLE / TAG_PRESERVED, @@ -64,6 +65,12 @@ grades the real fixtures all-PORTABLE. See `grader/README.md`. ## Scope and placement +S rungs are source-shape rungs: constructs that test how a source's data +conventions survive a round trip, independent of the expression ladder. S1 +adds no expression capability: it reuses M3-class `CASE` forms to carry a +source convention the spec cannot yet declare (#401), and a declared-sentinel +rung would supersede it. + Rungs M7 and M8 (window and offset functions: time intelligence and ratio-to-total) are held until the default NULL placement in window `ORDER BY` is settled (#587), and are not in this set. diff --git a/compliance/portability/grader/test_grade.py b/compliance/portability/grader/test_grade.py index dd674e65d..842a8dd02 100644 --- a/compliance/portability/grader/test_grade.py +++ b/compliance/portability/grader/test_grade.py @@ -18,7 +18,7 @@ """Outcome tests for the #576 fidelity grader. Each test builds a tiny input document and a synthetic returned document that -exercises exactly one outcome. The identity test runs the real posted M0-M6 fixtures +exercises exactly one outcome. The identity test runs the real posted M0-M6 and S1 fixtures through a no-op converter: returned unchanged, every element must grade PORTABLE. The manifest tests check that every element the manifest names can be found by kind and name in each variant, and that each primary variant uses the rung's @@ -150,13 +150,13 @@ def test_whitespace_is_not_a_difference(): assert _only(grade.grade(src, returned)).outcome == grade.PORTABLE -def test_identity_on_real_m0_m6_fixtures_is_all_portable(): +def test_identity_on_real_m0_m6_s1_fixtures_is_all_portable(): files = sorted( path - for rung in ("m0", "m1", "m2", "m3", "m4", "m5", "m6") + for rung in ("m0", "m1", "m2", "m3", "m4", "m5", "m6", "s1") for path in glob.glob(os.path.join(HERE, rung, "*.ossie.yaml")) ) - assert files, "no M0-M6 fixtures found" + assert files, "no M0-M6/S1 fixtures found" for path in files: document = grade._load(path) report = grade.grade(document, document) diff --git a/compliance/portability/manifest.yaml b/compliance/portability/manifest.yaml index dd37d3b1c..cf9e26c9c 100644 --- a/compliance/portability/manifest.yaml +++ b/compliance/portability/manifest.yaml @@ -163,3 +163,25 @@ rungs: reference_form_primary: qualified # the metric qualifies dataset.field; the fields reference sibling columns bare (intra-dataset) variants: - {id: M6.date_scalars, file: m6/m6_date_scalars.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} + + - id: S1 + description: source-defined sentinel values (#401) carried as portable recognition rules; measures whether each rule survives, not whether the sentinel is declared + elements_under_test: + - kind: field + name: customer_sales_area.customer_key + construct: initial key value '0000000000' mapped to NULL + - kind: field + name: customer_sales_area.is_delivery_blocked + construct: blank code as a real state (TRIM = '' is FALSE, not NULL) + - kind: field + name: customer_sales_area.planned_delivery_date + construct: initial DATS '00000000' recognised before CAST to DATE + - kind: field + name: customer_sales_area.is_open_ended + construct: open-ended validity marker '9999-12-31' as a business state + - kind: metric + name: customers_with_planned_date + construct: COUNT(DISTINCT CASE ...) that excludes the sentinel from "populated" + reference_form_primary: qualified # the metric qualifies dataset.field; the rule fields reference sibling columns bare (intra-dataset) + variants: + - {id: S1.sentinel_rules, file: s1/s1_sentinel_rules.ossie.yaml, tag: ANSI_SQL, reference_form: qualified, role: primary} diff --git a/compliance/portability/s1/s1_sentinel_rules.ossie.yaml b/compliance/portability/s1/s1_sentinel_rules.ossie.yaml new file mode 100644 index 000000000..4f5a8128e --- /dev/null +++ b/compliance/portability/s1/s1_sentinel_rules.ossie.yaml @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +# S1 ladder rung: source-defined sentinel values (issue #401). SAP-class +# systems store type-dependent initial values instead of NULL: a CHAR(10) +# customer key initial as '0000000000', a DATS date initial as '00000000', a +# CHAR delivery-block code whose blank is a real state ("not blocked", not +# "unknown"), and '9999-12-31' as an open-ended validity end. The spec has no +# construct to declare these meanings yet, so this rung carries each +# recognition rule as a portable expression and measures whether the RULE +# survives a converter round trip. It does not measure sentinel declaration. +# The raw fields resolve inside their own dataset (sibling columns); the +# metric uses the qualified form. Every literal here is a sentinel pattern, +# not a record. +version: "0.2.0.dev0" +name: s1_customer_sales_area +description: "S1: source-defined sentinel values carried as portable recognition rules." +datasets: + - name: customer_sales_area + source: samples.sap.customer_sales_area + fields: + - name: customer + description: "Customer key, CHAR(10) zero-padded; '0000000000' is the initial value." + expression: + dialects: + - dialect: ANSI_SQL + expression: customer + datatype: String + - name: delivery_block + description: "Delivery block code, CHAR(2); blank means not blocked, a real state." + expression: + dialects: + - dialect: ANSI_SQL + expression: delivery_block + datatype: String + - name: planned_delivery_date_raw + description: "DATS date as stored, 'YYYYMMDD'; '00000000' is the initial value." + expression: + dialects: + - dialect: ANSI_SQL + expression: planned_delivery_date_raw + datatype: String + - name: valid_to + description: "Validity end; '9999-12-31' means no validity end was specified." + expression: + dialects: + - dialect: ANSI_SQL + expression: valid_to + datatype: Date + - name: customer_key + description: "Rule: the initial key value is not a key." + expression: + dialects: + - dialect: ANSI_SQL + expression: CASE WHEN customer = '0000000000' THEN NULL ELSE customer END + datatype: String + - name: is_delivery_blocked + description: "Rule: blank is the 'not blocked' state, not an absence." + expression: + dialects: + - dialect: ANSI_SQL + expression: CASE WHEN TRIM(delivery_block) = '' THEN FALSE ELSE TRUE END + datatype: Boolean + - name: planned_delivery_date + description: "Rule: recognise the initial date before converting, so conversion cannot fail first." + expression: + dialects: + - dialect: ANSI_SQL + expression: CASE WHEN planned_delivery_date_raw = '00000000' THEN NULL ELSE CAST(planned_delivery_date_raw AS DATE) END + datatype: Date + - name: is_open_ended + description: "Rule: the open-ended marker is a business state, not a missing value." + expression: + dialects: + - dialect: ANSI_SQL + expression: CASE WHEN valid_to = '9999-12-31' THEN TRUE ELSE FALSE END + datatype: Boolean +metrics: + - name: customers_with_planned_date + description: "Counts only customers whose planned date is set; a sentinel must not count as populated." + expression: + dialects: + - dialect: ANSI_SQL + expression: COUNT(DISTINCT CASE WHEN customer_sales_area.planned_delivery_date_raw <> '00000000' THEN customer_sales_area.customer END) + datatype: Integer