Repository navigation
Conversation
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.
| ["CA", 65], | ||
| ["NY", 18] |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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.
|
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) 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. |
|
The expected values of
Each component is computed in its own branch, as in B.6: Two notes, now that #741 is on main:
|
| 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` |
There was a problem hiding this comment.
Follow-up to #725, addressing the non-blocking review comments.
Changes
a22_store_productivityanda23_store_productivity_by_stateon thestoresfixture. Before this PR, an engine that evaluates both components of a model-scoped metric over a singlestore_sales→storejoin passed the whole wide_table suite.a08only 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, andSUM(DISTINCT headcount)gives 415 / 5 = 83, so both wrong answers named in B.6 fail. The value is not exact, likea08's 162.5: catching theSUM(DISTINCT)plan needs equal headcounts, and 415 is odd, so no equal headcount gives a whole number.a23, bystore.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.stores.storegetsnumber_employees(5 for both stores), and bothstoresmodels get the field and a model-scopedstore_productivitymetric. The metric matches the TPC-DS one, withCAST(... AS DOUBLE)as inretail'srevenue_per_customer, so the cases test fan-out and not division semantics. Only a column is added: no existing row changes, soa16–a21ande22–e25are unaffected.storerow". In real TPC-DS data,storekeeps 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-DSstore_productivitymetric itself, and is out of scope here.wide_table_semantics.md.storesfixture section, plus thestores.sqlheader, mention B.6 and the new cases.Testing
make compliance-validate: 12 of 12 files pass.make validateandmake spec-checkpass.stores.sqlinto DuckDB and computeda22anda23with the lowering of Sections 5.2–5.5 (one branch per home dataset, keys from the union of branches). Both matchexpected.json. The flat-join andSUM(DISTINCT)plans return 16.6 / 83 and 21.67 / 9, so they fail the cases.