diff --git a/compliance/portability/README.md b/compliance/portability/README.md index 3ad9f35c..dfa4a233 100644 --- a/compliance/portability/README.md +++ b/compliance/portability/README.md @@ -42,6 +42,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, carried with their expressions inlined (composition through `AGG(dataset.metric)` is not tested by this rung) | | 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, @@ -50,6 +51,12 @@ DROPPED-diagnosed, DROPPED-silent, REJECTED). `grader/grade.py` implements it and `grader/test_grade.py` has one test per outcome plus an identity check that grades the real fixtures all-PORTABLE. See `grader/README.md`. +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. + ## Design rules - **Portable dialect only.** Every fixture is authored in `ANSI_SQL` or diff --git a/compliance/portability/grader/test_grade.py b/compliance/portability/grader/test_grade.py index 30199ea9..ca173e9a 100644 --- a/compliance/portability/grader/test_grade.py +++ b/compliance/portability/grader/test_grade.py @@ -18,7 +18,7 @@ """Outcome tests for the portability fidelity grader (apache/ossie-converters#24). 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 @@ -365,13 +365,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 10a4c68f..42d80307 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 00000000..0595dcb1 --- /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.3.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