Skip to content

test(compliance): add the Layer 2 query of each wide table case - #747

Merged
christianeu-db merged 2 commits into
apache:mainfrom
ekut:wide-table-ossie-sql
Nov 19, 2026
Merged

christianeu-db merged 2 commits into
apache:mainfrom
ekut:wide-table-ossie-sql

Conversation

@ekut

@ekut ekut commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 (a01 to a21) gets a query.ossie.sql: the Layer 2 query of the Section 5 lowering of its query.json. The 25 error cases raise an error instead of returning rows, so they get none.

For example, a05_groups_from_orders/query.json is

{
  "dimensions": ["customers.region"],
  "metrics": ["orders.total_revenue"]
}

and its query.ossie.sql, below the license header, is

-- a05. Groups come from the metric's dataset
-- The Section 5 lowering of query.json. Case notes: ../README.md.
-- Spec: 5.4, 6.1
-- ----------------------------------------------------------------------------
SELECT c.region, AGG(o.total_revenue) AS total_revenue
FROM retail_model.orders o
LEFT JOIN retail_model.customers c ON o.customer_id = c.customer_id
GROUP BY c.region;

The comment header is shorter than in compliance/query/cases. The title, question, and behavior of each case are in cases/README.md (#741), so the file names the case and points there.

Other changes:

  • The three models are renamed to retail_model, stores_model, and stores_ambiguous_model, after their files. As with scott_model over the schema scott in compliance/query, retail_model.orders in a query names a dataset of the model, and retail.orders the table beneath it. Nothing else in the repository reads these names.
  • compliance/wide_table/README.md describes 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 a COUNT(*) needs 0, a list of keys and a present column are used (a02, a03). a08 evaluates the two components of revenue_per_customer with plain aggregates. Each of its branches reads one dataset without a join, so a plain aggregate gives the value that AGG() gives.

Open question: #742 adds a22 and a23. Whichever PR lands second should add their query.ossie.sql. In a23, the store_sales component of store_productivity is in a branch that joins store. There a plain aggregate equals AGG() only when the data keeps the declared cardinality, and Layer 2 has no portable syntax to define a measure inside a query (TO MEASURE is illustrative). How should a23 write that component?

Checks:

  • With the expander of the 502-expander branch (f91b5a5, View expander #502) on DuckDB, 16 of the 21 queries return the rows of expected.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: a12 joins relations of a model without AGG(), and a16, a19, a20, and a21 use date_dim.year, whose expression is d_year.
  • A script replaced each AGG(m) with the expression of m, each field with its expression, and each dataset with its source, then ran the queries on DuckDB. All 21 return the rows of expected.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.py passes on the three models, and dev/check-license passes.

cc @christianeu-db @jbonofre

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 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 @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

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 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, @ekut LGTM!

@christianeu-db
christianeu-db merged commit d5822ed into apache:main Nov 19, 2026
5 checks passed
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.

2 participants