Skip to content

test(compliance): add S1, a source-shape rung for sentinel-value recognition rules - #761

Open
marioapiphani wants to merge 13 commits into
apache:mainfrom
marioapiphani:feat/compliance-sap-sentinel-rung
Open

marioapiphani wants to merge 13 commits into
apache:mainfrom
marioapiphani:feat/compliance-sap-sentinel-rung

Conversation

@marioapiphani

Copy link
Copy Markdown
Contributor

Summary

Adds rung S1 to compliance/portability: a fixture whose fields carry the sentinel conventions common in ERP-sourced data, and whose elements under test are the rules that recognise them. It tests whether a recognition rule survives a round trip, not whether a sentinel can be declared — the spec has no construct for that yet (#401), so this is the honest subset that fits the grader as it is.

The fixture is one customer-sales-area-shaped dataset (same shape as the Business Partner slice used by apache/ossie-converters#54 and #130). Four raw fields, four rule fields as CASE expressions tagged ANSI_SQL, like every primary fixture on the ladder, one metric:

  • initial key ('0000000000', CHAR 10) → NULL
  • blank delivery-block (CHAR 2, blank = "not blocked") → kept as a state, not nulled: a sentinel that is not absence
  • initial date ('00000000') recognised before CAST, which would otherwise fail
  • open-ended validity marker ('9999-12-31') → "no specified validity end", a business state
  • a count of customers with a planned delivery date that excludes the initial date ('00000000') from the populated total

All literals are patterns; no records.

S rather than M7: M7/M8 are reserved for window functions, and this rung adds no expression capability. S = source-shape rungs — constructs that test how a source's data conventions survive, independent of the expression ladder. README has a row and a paragraph.

Verified: validate.py passes the fixture; the grader's tests pass; a no-op round trip grades all elements PORTABLE (sanity, not evidence). Manifest uses the elements_under_test shape from #631.

Related Issues

#401 (sentinel declaration — the construct this rung is waiting for), #693 (keys/relationships as elements under test), #46 (thread).

Checklist

  • fixture validates against the current schema
  • grader tests pass
  • README updated
  • no grader or vocabulary change

🤖 Generated with Claude Code

MrBlack1995 and others added 13 commits October 23, 2026 18:13
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
…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>
A metric expression cannot refer to other metrics (core-spec/spec.md,
Metric Scoping; expression_language.md), and since apache#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 <no-reply@databricks.com>
…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 <no-reply@databricks.com>
…grade them

Since apache#486 a model-scoped metric must reference fields as dataset.field,
and since apache#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 <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>
…les (apache#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 apache#631.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
apache#631 landed on main in rebased form. Conflicts are resolved to main's
side for every ladder file; the S1 README row and paragraph, manifest
rung and identity-test entry are reapplied on top. The S1 fixture's
version moves to 0.3.0.dev0, which the current schema requires.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@marioapiphani

Copy link
Copy Markdown
Contributor Author

@MrBlack1995 @jbonofre I can't request reviewers from my account, so a ping instead: this is the S1 rung discussed on #693 and #46, rebased on #631. Four files, no grader or vocabulary change. Happy to adjust the S naming or placement if you'd rather it sit elsewhere in the ladder.

@MrBlack1995 MrBlack1995 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for building on the ladder, and for keeping it to the rules the grader can already measure. I like the S prefix: it says this is about source conventions, not a new expression capability, and the README paragraph makes the #401 dependency explicit. Checked here: the fixture passes validate.py, the 50 grader tests pass, and it merges cleanly with current main.

Three points on the fixture, all small; the first is the one I would fix before merge, since the rung is about portable rules:

  1. CAST of a DATS string is not portable. expression_language.md (Date/Time Construction) only promises ISO-8601 strings (YYYY-MM-DD) to parse the same everywhere; '20261118' parses on some engines and fails or returns NULL on others. Building the ISO form first keeps the rule portable and still recognises the sentinel before the cast (inline on line 84).
  2. A NULL delivery block comes out as blocked. TRIM(NULL) = '' is NULL, so the CASE falls to ELSE TRUE. Extracted SAP data often has NULL where the source had blanks, so COALESCE(TRIM(delivery_block), '') = '' keeps "no block" for both (inline on line 77).
  3. valid_to is a Date compared to a string. DATE '9999-12-31' is the spec's typed literal and avoids relying on an implicit cast (inline on line 91).

I checked that all three suggested forms pass validate.py and keep the 50 tests green.

expression:
dialects:
- dialect: ANSI_SQL
expression: CASE WHEN planned_delivery_date_raw = '00000000' THEN NULL ELSE CAST(planned_delivery_date_raw AS DATE) END

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only ISO-8601 strings are portable for CAST(... AS DATE) (expression_language.md, Date/Time Construction), and DATS is YYYYMMDD. Something like this keeps the rule portable and still checks the sentinel first:

CASE WHEN planned_delivery_date_raw = '00000000' THEN NULL
     ELSE CAST(CONCAT(SUBSTRING(planned_delivery_date_raw, 1, 4), '-', SUBSTRING(planned_delivery_date_raw, 5, 2), '-', SUBSTRING(planned_delivery_date_raw, 7, 2)) AS DATE) END

expression:
dialects:
- dialect: ANSI_SQL
expression: CASE WHEN TRIM(delivery_block) = '' THEN FALSE ELSE TRUE END

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a NULL delivery_block, TRIM(...) = '' is NULL and this returns TRUE (blocked). COALESCE(TRIM(delivery_block), '') = '' treats NULL like blank, which matches the description.

expression:
dialects:
- dialect: ANSI_SQL
expression: CASE WHEN valid_to = '9999-12-31' THEN TRUE ELSE FALSE END

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid_to is declared Date, so DATE '9999-12-31' (the spec's typed literal) avoids comparing a date with a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants