Repository navigation
test(compliance): add the Layer 2 query of each wide table case - #747
Conversation
Each of the 21 cases that return rows gets query.ossie.sql: the Layer 2 query of the Section 5 lowering of its query.json, with a short header that points to cases/README.md. The 25 error cases get none. The three models are renamed after their files (retail_model, stores_model, stores_ambiguous_model), so that <model>.<dataset> in a query does not coincide with the schema of the fixture, as with scott_model over scott in compliance/query. year is quoted: YEAR is a reserved word in standard SQL. The README of the suite describes the new file.
christianeu-db
left a comment
There was a problem hiding this comment.
Thanks @ekut! The comment on the quoted year should be addressed before merging; the other is optional.
| -- The Section 5 lowering of query.json. Case notes: ../README.md. | ||
| -- Spec: 4, 5.4, B.3 | ||
| -- ---------------------------------------------------------------------------- | ||
| SELECT d."year", AGG(s.total_sales) AS total_sales |
There was a problem hiding this comment.
A quoted identifier matches exactly, so d."year" does not name the field year, which normalizes to YEAR (see the comparison table in expression_language.md). The same holds in a16, a20, and a21. The Ossie grammar has no YEAR keyword, and Appendix B.3 and the a20 filter write date_dim.year, so could we leave it unquoted?
Generally, could be nice if we avoided quoted identifiers in our tests
There was a problem hiding this comment.
Done in 4b373b4. year is unquoted in a16, a19, a20, and a21, and no query.ossie.sql has a quoted identifier now. The checks from the description give the same results. Direct replacement returns the rows of expected.txt for all 21 queries, and the 502-expander branch (f91b5a5) for the same 16. I removed the line about quoting from the description.
| refers to each dataset as `<model name>.<dataset name>`, as | ||
| [`../query/README.md`](../query/README.md) does, with the model of the case's | ||
| fixture. Run on that fixture, it returns the rows of `expected.txt`. Where a | ||
| branch reads one dataset without a join, as in `a08`, a plain aggregate stands |
There was a problem hiding this comment.
Not a blocker: on your a23 question, a model-scoped metric may call AGG(dataset.metric) (core spec, Metric Scoping, rule 6), and Section 5.2 evaluates that call as the dataset-scoped metric. So if #742 writes the numerator of store_productivity as AGG(store_sales.total_sales), a23 can use AGG(s.total_sales) in the branch that joins store
There was a problem hiding this comment.
Thanks, that answers it.
A quoted identifier matches exactly, so "year" does not name the field year, which normalizes to YEAR (expression_language.md, Comparison Table). The queries of a16, a19, a20, and a21 now write the field unquoted, and no query.ossie.sql has a quoted identifier.
christianeu-db
left a comment
There was a problem hiding this comment.
Thanks, @ekut LGTM!
Follow-up to #716: the second of the next steps in the review, as planned in #707.
Each of the 21 cases in
compliance/wide_table/cases/that return rows (a01toa21) gets aquery.ossie.sql: the Layer 2 query of the Section 5 lowering of itsquery.json. The 25 error cases raise an error instead of returning rows, so they get none.For example,
a05_groups_from_orders/query.jsonis{ "dimensions": ["customers.region"], "metrics": ["orders.total_revenue"] }and its
query.ossie.sql, below the license header, isThe comment header is shorter than in
compliance/query/cases. The title, question, and behavior of each case are incases/README.md(#741), so the file names the case and points there.Other changes:
retail_model,stores_model, andstores_ambiguous_model, after their files. As withscott_modelover the schemascottincompliance/query,retail_model.ordersin a query names a dataset of the model, andretail.ordersthe table beneath it. Nothing else in the repository reads these names.compliance/wide_table/README.mddescribes the new file.Queries with several branches combine them in one of the two plans of Sections 1.3 and 5.5. Where every metric has NULL as its empty-input value, branches meet in a
FULL JOIN(a01,a04,a16). Where aCOUNT(*)needs 0, a list of keys and apresentcolumn are used (a02,a03).a08evaluates the two components ofrevenue_per_customerwith plain aggregates. Each of its branches reads one dataset without a join, so a plain aggregate gives the value thatAGG()gives.Open question: #742 adds
a22anda23. Whichever PR lands second should add theirquery.ossie.sql. Ina23, thestore_salescomponent ofstore_productivityis in a branch that joinsstore. There a plain aggregate equalsAGG()only when the data keeps the declared cardinality, and Layer 2 has no portable syntax to define a measure inside a query (TO MEASUREis illustrative). How shoulda23write that component?Checks:
502-expanderbranch (f91b5a5, View expander #502) on DuckDB, 16 of the 21 queries return the rows ofexpected.txt. The other five need what the expander does not support yet, as listed in Reference implementation for rewriting Layer 2 and Layer 3 queries #707:a12joins relations of a model withoutAGG(), anda16,a19,a20, anda21usedate_dim.year, whose expression isd_year.AGG(m)with the expression ofm, each field with its expression, and each dataset with its source, then ran the queries on DuckDB. All 21 return the rows ofexpected.txt. Every join in these queries goes from the many side to a primary key, so no row repeats and the replacement gives the rows of the reference evaluation.validation/validate.pypasses on the three models, anddev/check-licensepasses.cc @christianeu-db @jbonofre