Skip to content

feat(compliance): add Layer 3 B.6 fan-out cases and polish B.6 - #742

Open
jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:docs/wide-table-b6-followup
Open

jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:docs/wide-table-b6-followup

Conversation

@jbonofre

@jbonofre jbonofre commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #725, addressing the non-blocking review comments.

Changes

  • New cases a22_store_productivity and a23_store_productivity_by_state on the stores fixture. Before this PR, an engine that evaluates both components of a model-scoped metric over a single store_sales → store join passed the whole wide_table suite. a08 only covers the case where a join loses rows (650 / 4 vs 650 / 3), not double counting.
    • a22, no dimensions: 415 / (5 + 5) = 41.5. A flat join gives 415 / 25 = 16.6, and SUM(DISTINCT headcount) gives 415 / 5 = 83, so both wrong answers named in B.6 fail. The value is not exact, like a08's 162.5: catching the SUM(DISTINCT) plan needs equal headcounts, and 415 is odd, so no equal headcount gives a whole number.
    • a23, by store.state: CA 325 / 5 = 65, NY 90 / 5 = 18. A flat join gives CA 325 / 15. The results are exact, as the query README recommends.
  • Fixture: stores.store gets number_employees (5 for both stores), and both stores models get the field and a model-scoped store_productivity metric. The metric matches the TPC-DS one, with CAST(... AS DOUBLE) as in retail's revenue_per_customer, so the cases test fan-out and not division semantics. Only a column is added: no existing row changes, so a16–a21 and e22–e25 are unaffected.
  • B.6 wording: "headcount is recorded per store" → "headcount per store row". In real TPC-DS data, store keeps one row per historical version of a store, so per store row is the accurate grain. Overcounting headcount across versions is a problem with the TPC-DS store_productivity metric itself, and is out of scope here.
  • B.6 wrapping: each paragraph is on one line, like the rest of wide_table_semantics.md.
  • Docs: the README intro, layout table, and stores fixture section, plus the stores.sql header, mention B.6 and the new cases.

Testing

  • make compliance-validate: 12 of 12 files pass. make validate and make spec-check pass.
  • I loaded stores.sql into DuckDB and computed a22 and a23 with the lowering of Sections 5.2–5.5 (one branch per home dataset, keys from the union of branches). Both match expected.json. The flat-join and SUM(DISTINCT) plans return 16.6 / 83 and 21.67 / 9, so they fail the cases.

Follow-up to apache#725.

- Add a22 and a23 on the stores fixture: the model-scoped metric
  store_productivity must count each store's headcount once, without
  dimensions and by store.state.
- Add number_employees to stores.store (5 per store) and the
  store_productivity metric to both stores models.
- B.6: say headcount is recorded per store row, and put each paragraph
  on one line like the rest of the file.
@github-actions github-actions Bot added the spec label Nov 16, 2026

@ayushtkn ayushtkn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanx @jbonofre LGTM, some non blocking suggestion

Comment on lines +9 to +10
["CA", 65],
["NY", 18]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

store_productivity is CAST(... AS DOUBLE) / ... with datatype: Float, so this is an approximate numeric. Written without a fraction it declares an exact one: README.md:139 in this directory says a JSON number with no fraction or exponent is exact, and ../../query/README.md:132 then requires exact numerics to be equal, with the 1e-9 relative tolerance applying only to approximate ones.

As written, a23 gets zero tolerance on a floating-point division, and an engine one ULP off 65.0 fails a case that is semantically correct. a22 in this PR has it right with 41.5, as does a08 with 162.5.
Maybe

     ["CA", 65.0],
     ["NY", 18.0]

"fixture": "stores",
"title": "Each group counts a store's headcount once",
"question": "What is the sales amount per employee by store state?",
"behavior": "Both components reach store, so each branch groups by state. CA has sales of 325 (SS1, SS2, SS4) and 5 employees, NY has 90 (SS3, SS5) and 5. Over a join from store_sales to store, CA's headcount counts three times and gives 325 / 15. Appendix B.6.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Each state has one store, so SUM(DISTINCT headcount) also gives 5 and still passes here — CA would be 325 / 5 = 65, the right answer. a22 is the case that catches that plan. Worth a clause in behavior saying so, since the README sentence this PR adds ("Cases a22 and a23 check that the model-scoped metric store_productivity counts it once") reads as though both cases cover both wrong plans.

@ashlearnnext-star

Copy link
Copy Markdown
Contributor

I checked the exact/approximate point raised by @ayushtkn. The point is correct.

The rule appears in README.md:139-140. The rule states: a JSON number with no fraction and no exponent is exact. A JSON number with a fraction or an exponent is approximate.

store_productivity has datatype Float in both store models. Its expression is:

CAST(SUM(store_sales.sales_amount) AS DOUBLE) / NULLIF(SUM(store.number_employees), 0)
This expression performs floating-point division. The result is approximate, not exact.

The file a23/expected.json writes ["CA", 65] and ["NY", 18]. These numbers have no fraction. Under the rule above, the test treats them as exact. An exact comparison applied to a floating-point division gives zero tolerance.

The file a22/expected.json, in the same PR, writes 41.5. This number has a fraction. The test treats it as approximate. This is correct.

Required fix: change a23/expected.json to use 65.0 and 18.0.

Additional note: PR #741 merged after this PR was opened. PR #741 requires new test cases to use expected.txt in the ost table format. It no longer accepts expected.json for new cases. When this PR rebases, a22 and a23 require conversion to expected.txt, in addition to the exact/approximate fix above.

@ekut

ekut commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

The expected values of a22 and a23 hold on an independent Layer 3 implementation. I ran both queries on ClickHouse with dactopus-ossie-clickhouse 0.17.0, on the rows of stores.sql and each of the two models from this branch:

Case Expected Result
a22_store_productivity 41.5 41.5
a23_store_productivity_by_state CA 65, NY 18 CA 65.0, NY 18.0

Each component is computed in its own branch, as in B.6: SUM(number_employees) over store, and SUM(sales_amount) over store_sales.

Two notes, now that #741 is on main:

@christianeu-db christianeu-db 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 @jbonofre! a22 and a23 still use the case layout from before #741 and #747. Happy to approve once they're converted.

Section 5.2, Section 6.1, and Appendix B. Appendix B.3 gives no rows, so the
`stores` data is chosen for its cases, and their expected results follow from
it.
it. Cases `a22` and `a23` evaluate the metric of Appendix B.6 on the `stores`

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.

Since #741 and #747, each case that returns rows has an expected.txt, a query.ossie.sql with the Layer 2 query of its lowering, and an entry in cases/README.md. a22 and a23 still have expected.json and none of the three. Could the rebase convert them (a08 has a two-branch lowering to start from)?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants