Skip to content

test(compliance): add additional relational query (layer 2) query test cases - #628

Merged
christianeu-db merged 8 commits into
apache:mainfrom
christianeu-db:relational-semantics-compliance-tests
Nov 6, 2026
Merged

christianeu-db merged 8 commits into
apache:mainfrom
christianeu-db:relational-semantics-compliance-tests

Conversation

@christianeu-db

@christianeu-db christianeu-db commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds cases A2-A12 and B1-B20 to the query compliance tests, in the case format that #632 merged. Each case is one directory under compliance/query/cases/ with query.ossie.sql, expected.sql, and reference.duckdb.sql.

The earlier version of this PR had all 29 cases in one file, relational_semantics.sql. #632 took case A1 from it and settled the format. This version moves the other 28 cases into that format, and the single file is gone.

  • A2-A12 (one relation): grouping, WHERE, HAVING/ORDER BY/LIMIT, scalar expressions over AGG(), NULL inputs, an empty input set, GROUP BY ALL, ROLLUP, CTEs, scalar subqueries, and two-stage aggregation.
  • B1-B8 (joins that repeat rows): many-to-one joins, filters on the joined relation, a top-N join, fan-out on the "one" side, in a self-join, through a range join, and in a three-way join, and a many-to-many join (chasm trap).
  • B9-B17 (join types): one self-join query with INNER, LEFT, RIGHT, FULL, and CROSS joins, and one dept-emp ratio with INNER and LEFT joins, a filter in ON, and a group with an empty input set.
  • B18-B20 (fan-out risk on a "one"-side measure): a WHERE filter, a non-distinct join-as-filter subquery, and a HAVING predicate, each over a measure of the "one" side, where a plain join-and-aggregate returns the wrong result.

Commits

The cases move without change. Each later commit makes one kind of change:

  1. Merge main. The conflict in compliance/query/README.md takes the version of test(compliance): add initial layer 2 query compliance test framework #632.
  2. Split relational_semantics.sql into case directories. Each Ossie query, reference query, and case header is copied without change. Each expected.sql gives the values of the old ASCII result table.
  3. Cast AVG and division results to an approximate type. The README of test(compliance): add initial layer 2 query compliance test framework #632 does not allow an exact numeric result whose scale is implementation-defined. avg_sal and avg_comm cast their argument before they average. A5 and B14-B16 cast before they divide, and A12 casts the argument of its outer AVG. A2 no longer returns avg_sal, as A1 does not. No other expected result changes.
  4. Name cases for what they show and add Question: lines. Only headers, directory names, and the README change. The expected.sql and reference.duckdb.sql files are pure renames.
  5. Describe the Section 9 recipe in the README, as @jbonofre suggested on test(compliance): add initial layer 2 query compliance test framework #632: within each output group, discard rows whose primary_key is NULL, keep one row per primary_key, and then aggregate.
  6. Use the Ossie expression language in the model and the casts. The casts use CAST(... AS DOUBLE), because the CAST of expression_language.md lists FLOAT and DOUBLE as its floating-point types. expected.sql keeps DOUBLE PRECISION for a typed NULL, because it is standard SQL. Every expression of scott_model.ossie.yaml now uses the portable form, expression: sql: ..., as the canonical examples do (docs: use portable sql fields in canonical examples #640). No expected result changes.

Names and English descriptions

@julianhyde suggested an English description for each query. Each query.ossie.sql header now has:

  • a title that states what the case shows, for example A9. ROLLUP evaluates a measure again for each grouping set.;
  • a Question: line, for example What is the average salary of each department, and of the whole company?.

The case directory names follow the same rule, for example a09_rollup_not_average_of_averages and b05_manager_counted_once. The README states that the question helps a reader and that the Ossie query is the ground truth.

Case B5 as an example:

-- B5. Fan-out in a self-join: each manager is counted once.
-- Question: For each job, how many employees have a manager, how many
--   managers do they report to, and what is the total salary of those
--   managers?
SELECT e.job,
       AGG(e.emp_count) AS emp_count,
       AGG(m.emp_count) AS managers,
       AGG(m.sum_sal) AS managers_sal
FROM scott_model.emp AS e
JOIN scott_model.emp AS m ON e.mgr = m.empno
GROUP BY e.job
ORDER BY e.job;

The 4 salesmen all report to BLAKE, so managers_sal for SALESMAN is 2850. A plain SUM(m.sal) over the joined rows gives 11400.

Out of scope

Verification

  • After commit 2, every line of each case header, Ossie query, and reference query is a line of relational_semantics.sql, and the rows of each expected.sql equal the old result table. In the final version, 27 of the 28 results still equal the old tables; A2 has one column less.
  • For each case, expected.sql gives the same result as reference.duckdb.sql on DuckDB 1.5.6 under the README comparison rules, and the column names of both are the aliases of query.ossie.sql.
  • For B1-B17, the independent queries that @ekut posted in this PR (each input set written out from Section 8.1 with EXISTS) also give the rows of expected.sql.
  • The README command that runs all reference queries exits with code 0.
  • uv run validation/validate.py compliance/query/scott/scott_model.ossie.yaml passes with the portable sql form.

Related Issues

Related: #354, #501, #502, #632, #640, #667.

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure (N/A: no spec change)
  • Spec changes have been discussed on the mailing list or in a linked issue (N/A)
  • Breaking changes to the spec are clearly called out in the summary (N/A: additive)

Ontology

  • Ontology changes in ontology/ are consistent with spec changes (N/A)
  • New or modified terms are defined and documented (N/A)

Converters

Validation

  • Validation rules in validation/ are updated if the spec changed (N/A)
  • New validation cases are covered by tests (N/A; the model passes validate.py)

Documentation

  • docs/ is updated to reflect any user-facing changes (N/A)
  • New features or behaviors are documented with examples where appropriate (compliance/query/README.md)
  • CONTRIBUTING.md is updated if the contribution process changed (N/A)

Examples

  • examples/ are added or updated for any new spec constructs (N/A)

Tests

  • All existing tests pass (pytest / CI green) (no code change; waiting for CI)
  • New functionality is covered by tests (this PR adds tests)

Compliance

  • ASF license headers are present on all new source files
  • No third-party dependencies are added without PMC/IPMC approval (DuckDB is necessary only to run the reference queries)
  • If third-party source code is vendored/copied (not just declared as a dependency), NOTICE and/or LICENSE have been updated per ASF policy (N/A)

AI disclosure

Per the ASF Generative Tooling Guidance, this contribution was prepared with AI assistance. I have reviewed and verified every change.

This pull request and its description were written by Isaac.

Add compliance/query/relational_semantics.sql, a DuckDB-runnable file of
29 test cases for core-spec/relational_semantics.md over the SCOTT
schema. Each case pairs an Ossie query that uses AGG() (commented out)
with an equivalent DuckDB query and its expected result.

- Part A (12 cases): AGG() on one relation: grouping, filters, HAVING,
  NULL and empty-input values, ROLLUP, CTE propagation, subqueries.
- Part B (17 cases): joins, including fan-out and many-to-many joins,
  and two queries run with each join type. The DuckDB queries use the
  reference evaluation strategy of Section 9.

The model scott_model (commented out) uses dataset-scoped metrics
(apache#591). The Ossie queries refer to its relations by two-part name, for
example scott_model.emp. This is a light version of the .ost test
format (apache#501) and view expander (apache#502).

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db
christianeu-db force-pushed the relational-semantics-compliance-tests branch from 1b4a613 to a3dcba5 Compare October 21, 2026 14:53
@christianeu-db

Copy link
Copy Markdown
Contributor Author

fyi: @julianhyde

@ekut

ekut commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

I checked the expected results against Section 8.1 by a second route. For B1-B17 I wrote each measure's input set out directly from 8.1, mostly as EXISTS over the join condition. This skips the Section 9 de-duplication. All 17 cases give the rows in the file. The queries are below; they run after the data section of the file.

Two values depend on how "host dialect" in Section 8.1 is read:

  • A5. Section 8.1 applies scalar operators to AGG() results "following the host dialect's standard scalar and NULL semantics". On ClickHouse 26.9, SUM(sal) / COUNT(*) stays Decimal(38, 2) and is truncated. sal_per_emp is then 2916.66 and 1566.66, where the file has 2916.67 and 1566.67.
  • A7 and B17. Section 8.1 gives an empty input set "the aggregate's standard empty-input value in the host SQL dialect". It then lists NULL for SUM and AVG. On ClickHouse with the default aggregate_functions_null_for_empty = 0, an ordinary SUM over no rows returns 0 and AVG returns nan.

Are the expected values in these cases meant for every engine, or for a host with standard SQL semantics?

A1-A4, A6, A8, A10-A12, B1-B9, B13 and B14 also return the expected rows on ClickHouse 26.9 with default settings (translated by SQLGlot 30.24.0). That may help pick the first cases to merge.

Queries for B1-B17
-- B1: many-to-one, the join repeats no emp row
SELECT d.dname, SUM(e.sal), COUNT(*) FROM scott.emp e JOIN scott.dept d USING (deptno) GROUP BY 1 ORDER BY 1;

-- B2: many-to-one, the join repeats no emp row
SELECT e.job, SUM(e.sal), COUNT(*) FROM scott.emp e JOIN scott.dept d USING (deptno) WHERE d.loc = 'NEW YORK' GROUP BY 1 ORDER BY 1;

-- B3
SELECT e.job, SUM(e.sal) FROM scott.emp e WHERE e.deptno IN
  (SELECT deptno FROM scott.emp GROUP BY deptno ORDER BY SUM(sal) DESC LIMIT 2) GROUP BY 1 ORDER BY 1;

-- B4
SELECT j.job,
  (SELECT COUNT(*) FROM scott.dept d WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = d.deptno AND e.job = j.job)),
  (SELECT COUNT(*) FROM scott.emp e WHERE e.job = j.job AND EXISTS (SELECT 1 FROM scott.dept d WHERE d.deptno = e.deptno))
  FROM (SELECT DISTINCT e.job FROM scott.emp e JOIN scott.dept d USING (deptno)) j ORDER BY 1;

-- B5
SELECT j.job,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.job = j.job AND EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT COUNT(*) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno AND e.job = j.job)),
  (SELECT SUM(m.sal) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno AND e.job = j.job))
  FROM (SELECT DISTINCT e.job FROM scott.emp e JOIN scott.emp m ON e.mgr = m.empno) j ORDER BY 1;

-- B6
SELECT g.deptno,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.deptno = g.deptno AND EXISTS (SELECT 1 FROM scott.salgrade s WHERE e.sal BETWEEN s.losal AND s.hisal)),
  (SELECT COUNT(*) FROM scott.salgrade s WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = g.deptno AND e.sal BETWEEN s.losal AND s.hisal))
  FROM (SELECT DISTINCT e.deptno FROM scott.emp e JOIN scott.salgrade s ON e.sal BETWEEN s.losal AND s.hisal) g ORDER BY 1;

-- B7
SELECT g.grade,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.sal BETWEEN g.losal AND g.hisal AND EXISTS (SELECT 1 FROM scott.dept d WHERE d.deptno = e.deptno)),
  (SELECT SUM(e.sal) FROM scott.emp e WHERE e.sal BETWEEN g.losal AND g.hisal AND EXISTS (SELECT 1 FROM scott.dept d WHERE d.deptno = e.deptno)),
  (SELECT COUNT(*) FROM scott.dept d WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = d.deptno AND e.sal BETWEEN g.losal AND g.hisal))
  FROM (SELECT DISTINCT s.grade, s.losal, s.hisal FROM scott.emp e JOIN scott.dept d USING (deptno) JOIN scott.salgrade s ON e.sal BETWEEN s.losal AND s.hisal) g ORDER BY 1;

-- B8: every emp row of the department appears on both sides
SELECT g.deptno,
  (SELECT SUM(e.sal) FROM scott.emp e WHERE e.deptno = g.deptno),
  (SELECT COUNT(*) FROM scott.emp c WHERE c.deptno = g.deptno)
  FROM (SELECT DISTINCT e.deptno FROM scott.emp e JOIN scott.emp c ON e.deptno = c.deptno) g ORDER BY 1;

-- B9
SELECT (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT COUNT(*) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno));

-- B10: every e row survives the LEFT JOIN
SELECT (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp),
  (SELECT COUNT(*) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno));

-- B11: every m row survives the RIGHT JOIN
SELECT (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp);

-- B12: every row of both sides survives the FULL JOIN
SELECT (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp), (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp);

-- B13: every row of both sides survives the CROSS JOIN
SELECT (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp), (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp);

-- B14
SELECT dc, ec, ss, ss / dc FROM (SELECT
  (SELECT COUNT(*) FROM scott.dept d WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = d.deptno)) dc,
  (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ec,
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ss);

-- B15: every dept row survives the LEFT JOIN
SELECT dc, ec, ss, ss / dc FROM (SELECT (SELECT COUNT(*) FROM scott.dept) dc,
  (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ec,
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ss);

-- B16: every dept row survives; only clerks match on the emp side
SELECT dc, ec, ss, ss / dc FROM (SELECT (SELECT COUNT(*) FROM scott.dept) dc,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.job = 'CLERK' AND EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ec,
  (SELECT SUM(sal) FROM scott.emp e WHERE e.job = 'CLERK' AND EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ss);

-- B17: every dept row survives the LEFT JOIN
SELECT d.dname,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.deptno = d.deptno),
  (SELECT SUM(sal) FROM scott.emp e WHERE e.deptno = d.deptno),
  (SELECT AVG(sal) FROM scott.emp e WHERE e.deptno = d.deptno)
  FROM scott.dept d ORDER BY 1;

@christianeu-db

Copy link
Copy Markdown
Contributor Author

I checked the expected results against Section 8.1 by a second route. For B1-B17 I wrote each measure's input set out directly from 8.1, mostly as EXISTS over the join condition. This skips the Section 9 de-duplication. All 17 cases give the rows in the file. The queries are below; they run after the data section of the file.

Two values depend on how "host dialect" in Section 8.1 is read:

  • A5. Section 8.1 applies scalar operators to AGG() results "following the host dialect's standard scalar and NULL semantics". On ClickHouse 26.9, SUM(sal) / COUNT(*) stays Decimal(38, 2) and is truncated. sal_per_emp is then 2916.66 and 1566.66, where the file has 2916.67 and 1566.67.
  • A7 and B17. Section 8.1 gives an empty input set "the aggregate's standard empty-input value in the host SQL dialect". It then lists NULL for SUM and AVG. On ClickHouse with the default aggregate_functions_null_for_empty = 0, an ordinary SUM over no rows returns 0 and AVG returns nan.

Are the expected values in these cases meant for every engine, or for a host with standard SQL semantics?

A1-A4, A6, A8, A10-A12, B1-B9, B13 and B14 also return the expected rows on ClickHouse 26.9 with default settings (translated by SQLGlot 30.24.0). That may help pick the first cases to merge.

Queries for B1-B17

-- B1: many-to-one, the join repeats no emp row
SELECT d.dname, SUM(e.sal), COUNT(*) FROM scott.emp e JOIN scott.dept d USING (deptno) GROUP BY 1 ORDER BY 1;

-- B2: many-to-one, the join repeats no emp row
SELECT e.job, SUM(e.sal), COUNT(*) FROM scott.emp e JOIN scott.dept d USING (deptno) WHERE d.loc = 'NEW YORK' GROUP BY 1 ORDER BY 1;

-- B3
SELECT e.job, SUM(e.sal) FROM scott.emp e WHERE e.deptno IN
  (SELECT deptno FROM scott.emp GROUP BY deptno ORDER BY SUM(sal) DESC LIMIT 2) GROUP BY 1 ORDER BY 1;

-- B4
SELECT j.job,
  (SELECT COUNT(*) FROM scott.dept d WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = d.deptno AND e.job = j.job)),
  (SELECT COUNT(*) FROM scott.emp e WHERE e.job = j.job AND EXISTS (SELECT 1 FROM scott.dept d WHERE d.deptno = e.deptno))
  FROM (SELECT DISTINCT e.job FROM scott.emp e JOIN scott.dept d USING (deptno)) j ORDER BY 1;

-- B5
SELECT j.job,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.job = j.job AND EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT COUNT(*) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno AND e.job = j.job)),
  (SELECT SUM(m.sal) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno AND e.job = j.job))
  FROM (SELECT DISTINCT e.job FROM scott.emp e JOIN scott.emp m ON e.mgr = m.empno) j ORDER BY 1;

-- B6
SELECT g.deptno,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.deptno = g.deptno AND EXISTS (SELECT 1 FROM scott.salgrade s WHERE e.sal BETWEEN s.losal AND s.hisal)),
  (SELECT COUNT(*) FROM scott.salgrade s WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = g.deptno AND e.sal BETWEEN s.losal AND s.hisal))
  FROM (SELECT DISTINCT e.deptno FROM scott.emp e JOIN scott.salgrade s ON e.sal BETWEEN s.losal AND s.hisal) g ORDER BY 1;

-- B7
SELECT g.grade,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.sal BETWEEN g.losal AND g.hisal AND EXISTS (SELECT 1 FROM scott.dept d WHERE d.deptno = e.deptno)),
  (SELECT SUM(e.sal) FROM scott.emp e WHERE e.sal BETWEEN g.losal AND g.hisal AND EXISTS (SELECT 1 FROM scott.dept d WHERE d.deptno = e.deptno)),
  (SELECT COUNT(*) FROM scott.dept d WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = d.deptno AND e.sal BETWEEN g.losal AND g.hisal))
  FROM (SELECT DISTINCT s.grade, s.losal, s.hisal FROM scott.emp e JOIN scott.dept d USING (deptno) JOIN scott.salgrade s ON e.sal BETWEEN s.losal AND s.hisal) g ORDER BY 1;

-- B8: every emp row of the department appears on both sides
SELECT g.deptno,
  (SELECT SUM(e.sal) FROM scott.emp e WHERE e.deptno = g.deptno),
  (SELECT COUNT(*) FROM scott.emp c WHERE c.deptno = g.deptno)
  FROM (SELECT DISTINCT e.deptno FROM scott.emp e JOIN scott.emp c ON e.deptno = c.deptno) g ORDER BY 1;

-- B9
SELECT (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT COUNT(*) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno));

-- B10: every e row survives the LEFT JOIN
SELECT (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp),
  (SELECT COUNT(*) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp m WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.mgr = m.empno));

-- B11: every m row survives the RIGHT JOIN
SELECT (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.emp m WHERE e.mgr = m.empno)),
  (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp);

-- B12: every row of both sides survives the FULL JOIN
SELECT (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp), (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp);

-- B13: every row of both sides survives the CROSS JOIN
SELECT (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp), (SELECT COUNT(*) FROM scott.emp), (SELECT SUM(sal) FROM scott.emp);

-- B14
SELECT dc, ec, ss, ss / dc FROM (SELECT
  (SELECT COUNT(*) FROM scott.dept d WHERE EXISTS (SELECT 1 FROM scott.emp e WHERE e.deptno = d.deptno)) dc,
  (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ec,
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ss);

-- B15: every dept row survives the LEFT JOIN
SELECT dc, ec, ss, ss / dc FROM (SELECT (SELECT COUNT(*) FROM scott.dept) dc,
  (SELECT COUNT(*) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ec,
  (SELECT SUM(sal) FROM scott.emp e WHERE EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ss);

-- B16: every dept row survives; only clerks match on the emp side
SELECT dc, ec, ss, ss / dc FROM (SELECT (SELECT COUNT(*) FROM scott.dept) dc,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.job = 'CLERK' AND EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ec,
  (SELECT SUM(sal) FROM scott.emp e WHERE e.job = 'CLERK' AND EXISTS (SELECT 1 FROM scott.dept d WHERE e.deptno = d.deptno)) ss);

-- B17: every dept row survives the LEFT JOIN
SELECT d.dname,
  (SELECT COUNT(*) FROM scott.emp e WHERE e.deptno = d.deptno),
  (SELECT SUM(sal) FROM scott.emp e WHERE e.deptno = d.deptno),
  (SELECT AVG(sal) FROM scott.emp e WHERE e.deptno = d.deptno)
  FROM scott.dept d ORDER BY 1;

Hi @ekut, thanks for trying these out! I think we'd be aiming for standard SQL semantics as much as possible. So, for the empty result case, we'd be following ISO/IEC 9075 (SQL), which says empty sum / avg => null.

The numeric point is an interesting one, esp. since a query optimization within the same engine can lead to slight differences due to floating point math. The most important thing for this suite is the query shapes. For numeric queries, we might need to work with simpler types (e.g. non-decimal) or accept some reasonable margin of error to account for precision

@jbonofre
jbonofre self-requested a review October 22, 2026 09:56
@justint-db

Copy link
Copy Markdown
Contributor

I agree that we should be aiming for sql compliance when using the standard Ossie dialect. I can update the references to host language in #354 to make this clearer. We should update the expression language spec to clarify this as well.

There will remain some gaps because the sql standard does not completely define function typing. For example, it allows AVG(float) to return either float or double.

@christianeu-db christianeu-db changed the title test(compliance): add DuckDB-runnable query tests for the Relational Query Interface [WIP] test(compliance): add DuckDB-runnable query tests for the Relational Query Interface Oct 23, 2026
@christianeu-db christianeu-db changed the title [WIP] test(compliance): add DuckDB-runnable query tests for the Relational Query Interface [WIP] test(compliance): add query tests for the Relational Query Interface (for discussion) Oct 23, 2026
-- writes it (spec Section 11.3).
-- ============================================================================

-- version: 0.2.0.dev0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it the same as this file, in the final test suite, would this be a ost file that references the model yaml?

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.

yes - we'll be pulling the cases from this file into the that folder. once it's ready, we'll migrate these cases to the .ost infrastructure

Comment on lines +597 to +598
SELECT 'avg payroll per dept' AS metric, AVG(dept_sal) AS amount
FROM (SELECT deptno, SUM(sal) AS dept_sal

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe further aggregations on top of AGG was one of the things discouraged in the proposal, remember seeing wording along the lines of "clients should avoid re aggregating...".

Isn't this query doing that? Should it be expressed differently in Ossie?

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.

There are a few distinct kinds of re-aggregation worth separating:

Re-aggregating results for efficiency. BI tools often compute aggregates in multiple places (e.g., on the server and locally) to minimize server queries. Pivot tables are a classic example: a tool might fetch cell-level aggregates and compute row/column subtotals locally by summing those results. This optimization is not generally safe for AGG(), since measures are not necessarily additive. This kind of re-aggregation is what the document warns against

Explicit two-pass aggregation. Sometimes the intended calculation genuinely requires multiple aggregation stages. For example, computing average regional sales requires first summing sales by region, then averaging those regional totals. SQL already supports this through subqueries or CTEs. We could eventually introduce first-class support for such calculations in Ossie, similar to Tableau's level-of-detail expressions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

got it.

-- WITH staff AS (
-- SELECT deptno, sum_sal AS payroll, emp_count AS headcount
-- FROM scott_model.emp
-- WHERE job IN ('CLERK', 'SALESMAN'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. Is adding job in the group by another case that should be added?
  2. Can we add complex expressions, like say sum(case sal > 100 then sal else 0) as high_sal_total, and similar one for count distinct?

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.

  1. that could be another case - the more interesting grouping cases are when grouping by a non-join key when joining two tables with measures
  2. yes - those would be good. we'd probably use the FILTER (WHERE ...) formulation since that's a bit more explicit

@julianhyde

Copy link
Copy Markdown
Contributor

Thank you for writing these tests. The format looks right. I like that you have included the Ossie query, expanded query, expected results, and a discussion of the algorithm (semantic rules) used to produce the expansion.

The expansion algorithm -- based on a spine of distinct entities and correlated scalar subqueries -- also looks right, though I have not analyzed every single query. (I expect that we will collectively focus on a particular query only when we have a point of disagreement.)

What do you think of adding an English description for each query? (I know it will make the corpus more verbose. And it will make some people think that this is a test for NL2SQL, which it is not. The Ossie query is the ground truth, not the English description.)

I now have a PR for .ost up; see #667.

@christianeu-db

Copy link
Copy Markdown
Contributor Author

@julianhyde thanks for the feedback! 100% agreed on adding some English descriptions. I'll put up a PR with a few more cases that we can use to iterate on the naming scheme.

Excited for the .ost PR #667 - I'll take a pass soon!

@julianhyde

julianhyde commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

I don't think I saw tests where the column being aggregated was on the "one" side and the filtering on the "many" side. An example would be

SELECT e.job, d.avg_dept_name_length)
FROM emp AS e
WHERE sal > 2000
JOIN dept AS d USING (deptno)
GROUP BY e.job

with the metric avg_dept_name_length defined in the obvious way: AVG(CHAR_LENGTH(d.dname)).

The data set does not make this easy. (There are no numeric attributes in the dept table.) I suggested the data set, so mea culpa.

The "Measures in SQL" paper has an example

WITH EnhancedCust o me rs AS
  (SELECT *,
      AVG(custAge) AS MEASURE avgAge
    FROM Customers)
SELECT o. prodName ,
    COUNT(*) AS orderCount ,
    AVG(c.custAge) AS weightedAvgAge,
    c.avgAge AS avgAge,
    c.avgAge AT (VISIBLE) AS visibleAvgAge
FROM Orders AS o
JOIN EnhancedCust om er s AS c USING ( custName )
WHERE c.custAge >= 18
GROUP BY o . prodName ;

with visible, non-visible, and weighted metrics. The "visible" keyword is not necessary in Ossie, because metrics are visible by default (i.e. rows are removed by the WHERE clause before calling the aggregate function), but I would like Ossie to have some gesture to say "non-visible" (In this case, what would mean giving the average age of all customers, not only those 18 or older, but only including in the query result products that have at least one customer aged 18 or older.)

I think there's a matrix where we want to test all valid combinations. I'm not sure exactly what the dimensions of that matrix are, but a rough guess: filtering on the one vs many side; no filtering; metrics that are defined in the one side, many side, or after the join; filters that remove none, some or all of the values of the "many" side of a relationship.

A fun and useful addition to the data set might be a pet table, such that any employee can have several cats and dogs. This puts emp on the "many" side of a foreign key, and therefore we can ask "What's the average salary of employees who have at least one cat?"

And, of course, the employee named SCOTT would have a cat named TIGER.

@christianeu-db

Copy link
Copy Markdown
Contributor Author

I don't think I saw tests where the column being aggregated was on the "one" side and the filtering on the "many" side. An example would be

SELECT e.job, d.avg_dept_name_length)
FROM emp AS e
WHERE sal > 2000
JOIN dept AS d USING (deptno)
GROUP BY e.job

with the metric avg_dept_name_length defined in the obvious way: AVG(CHAR_LENGTH(d.dname)).

The data set does not make this easy. (There are no numeric attributes in the dept table.) I suggested the data set, so mea culpa.

The "Measures in SQL" paper has an example

WITH EnhancedCust o me rs AS
  (SELECT *,
      AVG(custAge) AS MEASURE avgAge
    FROM Customers)
SELECT o. prodName ,
    COUNT(*) AS orderCount ,
    AVG(c.custAge) AS weightedAvgAge,
    c.avgAge AS avgAge,
    c.avgAge AT (VISIBLE) AS visibleAvgAge
FROM Orders AS o
JOIN EnhancedCust om er s AS c USING ( custName )
WHERE c.custAge >= 18
GROUP BY o . prodName ;

with visible, non-visible, and weighted metrics. The "visible" keyword is not necessary in Ossie, because metrics are visible by default (i.e. rows are removed by the WHERE clause before calling the aggregate function), but I would like Ossie to have some gesture to say "non-visible" (In this case, what would mean giving the average age of all customers, not only those 18 or older, but only including in the query result products that have at least one customer aged 18 or older.)

I think there's a matrix where we want to test all valid combinations. I'm not sure exactly what the dimensions of that matrix are, but a rough guess: filtering on the one vs many side; no filtering; metrics that are defined in the one side, many side, or after the join; filters that remove none, some or all of the values of the "many" side of a relationship.

A fun and useful addition to the data set might be a pet table, such that any employee can have several cats and dogs. This puts emp on the "many" side of a foreign key, and therefore we can ask "What's the average salary of employees who have at least one cat?"

And, of course, the employee named SCOTT would have a cat named TIGER.

Good call on the matrix & the missing 1:M example. I like your pet table extension. @julianhyde would you want to take a first pass on updating the model / adding in the table? I'm happy to review (am setting aside some time today to look over the ost extension)

@julianhyde

julianhyde commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

@christianeu-db My next task is to add some basic tests to .ost, including the expanded SQL and expected results. I plan to take your queries here and convert them to .ost format.

At first, I'll write a mock expander that simply parrots your SQL fragments, and that will get the test to "pass". But can you share the code / prompts that you used to create those fragments? Maybe I can easily convert it into Python that uses a SQLGlot AST.

After that, we'll be off to the races and can add more tests and test data sets. I'll make PETS my first PR of that nature.

christianeu-db and others added 5 commits November 5, 2026 06:55
Conflict: compliance/query/README.md. Take the version of main, which
apache#632 merged. It replaces the README of this branch.

Co-authored-by: Isaac <no-reply@databricks.com>
Move cases A2-A12 and B1-B17 into the case format of apache#632, one directory
per case. A1 is already on main.

- query.ossie.sql: the Ossie query and the case header, copied from
  relational_semantics.sql without change. B9-B16 also get the shared
  header of their group.
- reference.duckdb.sql: the DuckDB query, copied without change.
- expected.sql: the result of the DuckDB query. The values are the values
  of the ASCII result tables (doubles rounded to 2 places in the tables).
- scott_model.ossie.yaml: the avg_sal and avg_comm metrics of the model in
  relational_semantics.sql.

Co-authored-by: Isaac <no-reply@databricks.com>
The README of apache#632 does not allow an exact numeric result whose scale is
implementation-defined, such as AVG over an exact numeric or the division
of two exact numerics.

- avg_sal and avg_comm are AVG(CAST(... AS DOUBLE PRECISION)).
- A5 and B14-B16 cast before they divide. A12 casts the argument of its
  outer AVG.
- A2 no longer returns avg_sal, as A1 does not.

No other expected result changes.

Co-authored-by: Isaac <no-reply@databricks.com>
@julianhyde suggested an English description of each query (apache#628).

- Each query.ossie.sql header has a title that states what the case
  shows and a Question line that tells in English what the query asks.
  A1 gets a Question line too.
- The case directories take names from the same rule, for example
  a09_rollup -> a09_rollup_not_average_of_averages.
- The README describes the header and the naming rule. The question
  helps a reader; the Ossie query is the ground truth.

The queries, reference queries, and expected results do not change.

Co-authored-by: Isaac <no-reply@databricks.com>
… queries

As @jbonofre suggested on apache#632, the README now states the two steps of
Section 9 that the earlier wording left out: within each output group,
discard rows whose primary_key is NULL, keep one row per primary_key,
then aggregate. It also describes the shape of the join reference
queries (the joined and spine CTEs and one subquery per measure), and
each join reference query points to it.

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db christianeu-db changed the title [WIP] test(compliance): add query tests for the Relational Query Interface (for discussion) test(compliance): add query cases A2-A12 and B1-B17 Nov 5, 2026
@christianeu-db christianeu-db changed the title test(compliance): add query cases A2-A12 and B1-B17 test(compliance): add additional relational query (layer 2) query test cases Nov 5, 2026
…casts

- Cast to DOUBLE, not DOUBLE PRECISION. The CAST of the Ossie expression
  language lists FLOAT and DOUBLE as its floating-point types. The
  reference queries do the same. expected.sql keeps DOUBLE PRECISION for
  its typed NULL, because it is standard SQL.
- Write every expression of scott_model.ossie.yaml in the portable form,
  expression.sql, as the canonical examples do (apache#640). The model had
  only OSSIE_SQL_2026 entries in dialects.

No expected result changes.

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db
christianeu-db marked this pull request as ready for review November 5, 2026 15:22
@christianeu-db

Copy link
Copy Markdown
Contributor Author

@julianhyde I split out these cases into their own folders - let me know if these all resonate and then we could merge in prep of the OST refactor

B1-B3 report a measure of the "many" side over a many-to-one join, so a
plain join-and-aggregate returns the same result and does not exercise the
grain guarantee. These three cases put a measure of the "one" side where a
fan-out inflates it, each through a different clause:

- B18: a WHERE filter restricts a "one"-side measure that the join fans out.
- B19: a join to a non-distinct filter subquery does not inflate a measure
  (the duplication comes from the filter relation, not a finer-grained
  table), covering the closure corollary of Section 8.4.
- B20: a HAVING predicate over a fanned-out "one"-side measure, where a
  wrong grain changes the result set, not only the values.

Each case reuses an existing metric, so the model is unchanged. For each,
expected.sql equals reference.duckdb.sql on DuckDB, and a plain
join-and-aggregate diverges (values noted in each header).

Co-authored-by: Isaac <no-reply@databricks.com>
@julianhyde

Copy link
Copy Markdown
Contributor

I am conflicted about the decision to break into separate files, and with the amount of boilerplate in general. If tests are concise, you can fit several on the same page, and therefore see the contrast between, say, a join being INNER or LEFT.

The choice of the scott-tiger schema, with small tables with few columns and short data values, was intentional. In the interests of conciseness, I would also remove the expanded SQL from a lot of tests, and just check in the results.

The .ost format makes it easier to put lots of tests in the same file. Conflicting changes (e.g. one person updating a query's results while another person adds another five queries) can generally be resolved by basic tools like git rebase.

Speaking of conflicts, I have started working on #502 in my https://github.com/julianhyde/ossie/tree/502-expander branch. It builds on my PR #667 for case #501 but it also translates to .ost the .sql files you added in #628. Maybe we should pause our work, synchronize, and work in .ost from now on.

@christianeu-db

Copy link
Copy Markdown
Contributor Author

I am conflicted about the decision to break into separate files, and with the amount of boilerplate in general. If tests are concise, you can fit several on the same page, and therefore see the contrast between, say, a join being INNER or LEFT.

The choice of the scott-tiger schema, with small tables with few columns and short data values, was intentional. In the interests of conciseness, I would also remove the expanded SQL from a lot of tests, and just check in the results.

The .ost format makes it easier to put lots of tests in the same file. Conflicting changes (e.g. one person updating a query's results while another person adds another five queries) can generally be resolved by basic tools like git rebase.

Speaking of conflicts, I have started working on #502 in my https://github.com/julianhyde/ossie/tree/502-expander branch. It builds on my PR #667 for case #501 but it also translates to .ost the .sql files you added in #628. Maybe we should pause our work, synchronize, and work in .ost from now on.

@julianhyde Agreed, let's move full steam ahead with OST going forward.

As a tactical step, would you be OK with landing these cases for now? They'd give us a starting point for compliance testing and concrete examples of query shapes in the repo. We can incrementally replace them with equivalent .ost cases as those become available.

I'm also planning to update the website to mention compliance testing. While the current structure is far from ideal, these cases provide substantially more coverage than the single trivial case merged today.

Otherwise, I agree with all your points. I particularly like the idea of grouping related cases in a single file to illustrate how different query variations behave.

@julianhyde

Copy link
Copy Markdown
Contributor

Sure, you can land these cases for now. But then please pause your development, because to complete #502 I will need to convert all of them to .ost format, deleting all the .sql files, and make sure that the view expander can handle the expansion.

After 502 lands we can move tests around, remove boilerplate, etc.

@julianhyde

Copy link
Copy Markdown
Contributor

By the way, you'll notice that in #502 I added a PET table:

create table scott.pet as
select cast(pname as varchar(10)) as pname,
    cast(empno as smallint) as empno,
    cast(species as varchar(7)) as species,
    cast(age as tinyint) as age
from (values
    ('SNOOPY',  7499, 'DOG',     7),
    ('FELIX',   7566, 'CAT',     5),
    ('HAMMY',   7876, 'HAMSTER', 1),
    ('OREO',    7566, 'CAT',     2),
    ('RUBY',    7566, 'DOG',     7),
    ('STEALTH', 7902, 'CAT',     5),
    ('TIGER',   7788, 'CAT',     3),
    ('TRAMP',   null, 'DOG',     4)) as t (pname, empno, species, age);

It makes it easier to express fanout queries. (The current fanout queries self-join to EMP on MGR.)

@christianeu-db

Copy link
Copy Markdown
Contributor Author

@julianhyde sounds good - I'll merge this & pause. Then, my no. 1 goal on these compliance suites is to help you land #501 and #502

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

All 32 reference queries give their expected.sql rows under the README's comparison rules on DuckDB 2.0.0 as well, and the joined-row counts and plain-aggregate figures the headers quote, B4 through B20, come out as written. The model also passes today's validate.py, which has #677 since your merge commit. One small thing, not blocking: in A4 the HAVING leaves exactly three jobs, so LIMIT 3 never cuts a row and an implementation that ignores LIMIT still passes the case; LIMIT 2, with the header's "three" adjusted, would make it bite.

@christianeu-db
christianeu-db merged commit f28692a into apache:main Nov 6, 2026
5 checks passed
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 7, 2026
…che#502)

Add a view expander, which translates a query over an Ossie model
into an equivalent query over the model's tables, and functions that
let a script use it:

* `modelInline(name, yaml)` defines a model from Ossie YAML, parsed
  and validated by the apache-ossie package. Each dataset is a
  relation in schema `name`, such as `scott_model.emp`.
* `createView(name, sql)` defines a view.
* `expand(sql)` returns the expansion of a query.
* `executeExpand(sql)` expands a query and executes the expansion.
  Its output has two parts: the expansion, then the result. A
  command may now have several outputs, each matched by its own
  rules.

A query that reads a model or a view is expanded before it is
executed. The expander parses with sqlglot. It replaces a relation
of a model with its dataset's source, each `AGG(m)` (or
`MEASURE(m)`) with the expression of metric `m`, and a view with its
query. It does not support joins of a model's relations yet.

Add a `doubleDigits` property that rounds doubles in tables to a
given number of digits after the point, halves away from zero, as
SQL's `ROUND` does. `set` now takes a literal of any kind, and checks
it against the property's type.

Add `compliance/query/relational_semantics.ost`, which translates
cases A1 to A3 of the compliance queries in apache#628 into `.ost` form,
and run it in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 7, 2026
…12 (apache#502)

Add cases A4 to A12 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`, so that all of Part A
runs.

To support A10, the expander now expands each SELECT after the
SELECTs within it, and records the measures of its output. A
subquery or CTE that projects a measure without evaluating it passes
the measure through: it projects, instead, the columns that the
measure's expression needs, under a new name if the subquery uses
the column's name for something else, and the enclosing query
evaluates the measure. `*` passes every measure through.

A metric that has no expression in a dialect that the expander can
read is now an error only if a query evaluates it.

The expansion keeps `NULLS FIRST` and `NULLS LAST` as the query
wrote them. sqlglot omits them where they are DuckDB's default, but
the expansion should not rely on the defaults of a particular
database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 7, 2026
…1 to B5 (apache#502)

A join can repeat a row of a measure's relation, and a plain
aggregate would count each copy. Expand a query that joins relations
and evaluates measures by the reference strategy of Section 9 of the
spec. A CTE "joined" has the query's FROM, JOIN and WHERE clauses,
and projects the grouping keys and, for each relation whose measures
the query evaluates, its row-identity key (the dataset's primary
key) and the columns that the measures need. A CTE "spine" has one
row per group. Each AGG(m) becomes a correlated subquery that
reduces the group's joined rows to one per key, ignoring rows whose
key is NULL, then applies m's aggregate.

The expander does not yet support, in a join, measures of a
subquery, plain aggregates, GROUP BY ALL, ROLLUP, CUBE and GROUPING
SETS, nor a query that passes measures through a join.

The expansion now writes "x IS NOT NULL", not "NOT x IS NULL".

Add cases B1 to B5 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`. Their results, and
those of A1 to A12, are the same as the expected results in apache#628.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 7, 2026
Add cases B6 to B17 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`: a range join, fan-out
on two sides of a three-way join, a many-to-many join, one self-join
query with each join type, and one dept-emp query with inner and
outer joins. All 29 cases of apache#628 now run, and give the same results
as its expected results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 7, 2026
…#502)

compliance/query now has the query compliance cases of apache#628, one
directory per case, with a model, scott/scott_model.ossie.yaml, in
which expressions have the form "sql", and AVG casts its argument to
DOUBLE. Generate the cases of relational_semantics.ost from the
cases' query.ossie.sql files, and its model from the upstream model,
with the dataset pet added. This adds cases B18 to B20, and updates
the queries of A1, A2, A5, A12, and B14 to B16, and the comments of
every case. The results of all 32 cases equal those of the cases'
expected.sql.

Cases B5a, B8a and B9a to B13a, the note after B1, and the
introductions of B9 to B13 and B14 to B17 remain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ekut added a commit to Dactopus/dactopus-ossie-clickhouse that referenced this pull request Nov 10, 2026
Of the suite's 32 cases, 8 are asked as questions and return the expected
result, 3 are asked and refused (a metric of the one side grouped or
filtered by the many side), and 21 use a form of query no question has;
each is named with that form. The weekly canary job also checks out
core-spec, which two canaries read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ekut added a commit to Dactopus/dactopus-ossie-clickhouse that referenced this pull request Nov 10, 2026
Of the suite's 32 cases, 8 are asked as questions and return the expected
result, 3 are asked and refused (a metric of the one side grouped or
filtered by the many side), and 21 use a form of query no question has;
each is named with that form. The weekly canary job also checks out
core-spec, which two canaries read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 12, 2026
…che#502)

Add a view expander, which translates a query over an Ossie model
into an equivalent query over the model's tables, and functions that
let a script use it:

* `modelInline(name, yaml)` defines a model from Ossie YAML, parsed
  and validated by the apache-ossie package. Each dataset is a
  relation in schema `name`, such as `scott_model.emp`.
* `createView(name, sql)` defines a view.
* `expand(sql)` returns the expansion of a query.
* `executeExpand(sql)` expands a query and executes the expansion.
  Its output has two parts: the expansion, then the result. A
  command may now have several outputs, each matched by its own
  rules.

A query that reads a model or a view is expanded before it is
executed. The expander parses with sqlglot. It replaces a relation
of a model with its dataset's source, each `AGG(m)` (or
`MEASURE(m)`) with the expression of metric `m`, and a view with its
query. It does not support joins of a model's relations yet.

Add a `doubleDigits` property that rounds doubles in tables to a
given number of digits after the point, halves away from zero, as
SQL's `ROUND` does. `set` now takes a literal of any kind, and checks
it against the property's type.

Add `compliance/query/relational_semantics.ost`, which translates
cases A1 to A3 of the compliance queries in apache#628 into `.ost` form,
and run it in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 12, 2026
…12 (apache#502)

Add cases A4 to A12 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`, so that all of Part A
runs.

To support A10, the expander now expands each SELECT after the
SELECTs within it, and records the measures of its output. A
subquery or CTE that projects a measure without evaluating it passes
the measure through: it projects, instead, the columns that the
measure's expression needs, under a new name if the subquery uses
the column's name for something else, and the enclosing query
evaluates the measure. `*` passes every measure through.

A metric that has no expression in a dialect that the expander can
read is now an error only if a query evaluates it.

The expansion keeps `NULLS FIRST` and `NULLS LAST` as the query
wrote them. sqlglot omits them where they are DuckDB's default, but
the expansion should not rely on the defaults of a particular
database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 12, 2026
…1 to B5 (apache#502)

A join can repeat a row of a measure's relation, and a plain
aggregate would count each copy. Expand a query that joins relations
and evaluates measures by the reference strategy of Section 9 of the
spec. A CTE "joined" has the query's FROM, JOIN and WHERE clauses,
and projects the grouping keys and, for each relation whose measures
the query evaluates, its row-identity key (the dataset's primary
key) and the columns that the measures need. A CTE "spine" has one
row per group. Each AGG(m) becomes a correlated subquery that
reduces the group's joined rows to one per key, ignoring rows whose
key is NULL, then applies m's aggregate.

The expander does not yet support, in a join, measures of a
subquery, plain aggregates, GROUP BY ALL, ROLLUP, CUBE and GROUPING
SETS, nor a query that passes measures through a join.

The expansion now writes "x IS NOT NULL", not "NOT x IS NULL".

Add cases B1 to B5 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`. Their results, and
those of A1 to A12, are the same as the expected results in apache#628.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 12, 2026
Add cases B6 to B17 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`: a range join, fan-out
on two sides of a three-way join, a many-to-many join, one self-join
query with each join type, and one dept-emp query with inner and
outer joins. All 29 cases of apache#628 now run, and give the same results
as its expected results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 12, 2026
…#502)

compliance/query now has the query compliance cases of apache#628, one
directory per case, with a model, scott/scott_model.ossie.yaml, in
which expressions have the form "sql", and AVG casts its argument to
DOUBLE. Generate the cases of relational_semantics.ost from the
cases' query.ossie.sql files, and its model from the upstream model,
with the dataset pet added. This adds cases B18 to B20, and updates
the queries of A1, A2, A5, A12, and B14 to B16, and the comments of
every case. The results of all 32 cases equal those of the cases'
expected.sql.

Cases B5a, B8a and B9a to B13a, the note after B1, and the
introductions of B9 to B13 and B14 to B17 remain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 18, 2026
…che#502)

Add a view expander, which translates a query over an Ossie model
into an equivalent query over the model's tables, and functions that
let a script use it:

* `modelInline(name, yaml)` defines a model from Ossie YAML, parsed
  and validated by the apache-ossie package. Each dataset is a
  relation in schema `name`, such as `scott_model.emp`.
* `createView(name, sql)` defines a view.
* `expand(sql)` returns the expansion of a query.
* `executeExpand(sql)` expands a query and executes the expansion.
  Its output has two parts: the expansion, then the result. A
  command may now have several outputs, each matched by its own
  rules.

A query that reads a model or a view is expanded before it is
executed. The expander parses with sqlglot. It replaces a relation
of a model with its dataset's source, each `AGG(m)` (or
`MEASURE(m)`) with the expression of metric `m`, and a view with its
query. It does not support joins of a model's relations yet.

Add a `doubleDigits` property that rounds doubles in tables to a
given number of digits after the point, halves away from zero, as
SQL's `ROUND` does. `set` now takes a literal of any kind, and checks
it against the property's type.

Add `compliance/query/relational_semantics.ost`, which translates
cases A1 to A3 of the compliance queries in apache#628 into `.ost` form,
and run it in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 18, 2026
…12 (apache#502)

Add cases A4 to A12 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`, so that all of Part A
runs.

To support A10, the expander now expands each SELECT after the
SELECTs within it, and records the measures of its output. A
subquery or CTE that projects a measure without evaluating it passes
the measure through: it projects, instead, the columns that the
measure's expression needs, under a new name if the subquery uses
the column's name for something else, and the enclosing query
evaluates the measure. `*` passes every measure through.

A metric that has no expression in a dialect that the expander can
read is now an error only if a query evaluates it.

The expansion keeps `NULLS FIRST` and `NULLS LAST` as the query
wrote them. sqlglot omits them where they are DuckDB's default, but
the expansion should not rely on the defaults of a particular
database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 18, 2026
…1 to B5 (apache#502)

A join can repeat a row of a measure's relation, and a plain
aggregate would count each copy. Expand a query that joins relations
and evaluates measures by the reference strategy of Section 9 of the
spec. A CTE "joined" has the query's FROM, JOIN and WHERE clauses,
and projects the grouping keys and, for each relation whose measures
the query evaluates, its row-identity key (the dataset's primary
key) and the columns that the measures need. A CTE "spine" has one
row per group. Each AGG(m) becomes a correlated subquery that
reduces the group's joined rows to one per key, ignoring rows whose
key is NULL, then applies m's aggregate.

The expander does not yet support, in a join, measures of a
subquery, plain aggregates, GROUP BY ALL, ROLLUP, CUBE and GROUPING
SETS, nor a query that passes measures through a join.

The expansion now writes "x IS NOT NULL", not "NOT x IS NULL".

Add cases B1 to B5 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`. Their results, and
those of A1 to A12, are the same as the expected results in apache#628.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 18, 2026
Add cases B6 to B17 of the compliance queries in apache#628 to
`compliance/query/relational_semantics.ost`: a range join, fan-out
on two sides of a three-way join, a many-to-many join, one self-join
query with each join type, and one dept-emp query with inner and
outer joins. All 29 cases of apache#628 now run, and give the same results
as its expected results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianhyde added a commit to julianhyde/ossie that referenced this pull request Nov 18, 2026
…#502)

compliance/query now has the query compliance cases of apache#628, one
directory per case, with a model, scott/scott_model.ossie.yaml, in
which expressions have the form "sql", and AVG casts its argument to
DOUBLE. Generate the cases of relational_semantics.ost from the
cases' query.ossie.sql files, and its model from the upstream model,
with the dataset pet added. This adds cases B18 to B20, and updates
the queries of A1, A2, A5, A12, and B14 to B16, and the comments of
every case. The results of all 32 cases equal those of the cases'
expected.sql.

Cases B5a, B8a and B9a to B13a, the note after B1, and the
introductions of B9 to B13 and B14 to B17 remain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

6 participants