Skip to content

test(compliance): add initial layer 2 query compliance test framework - #632

Merged
christianeu-db merged 11 commits into
apache:mainfrom
christianeu-db:relational-compliance-a1
Oct 30, 2026
Merged

christianeu-db merged 11 commits into
apache:mainfrom
christianeu-db:relational-compliance-a1

Conversation

@christianeu-db

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

Copy link
Copy Markdown
Contributor

Summary

The goal of this PR is to merge one small example and use it to bootstrap the query compliance tests, starting with the Relational Query Interface (#354).

The test cases in this PR are deliberately few. The draft #628 has 29 cases for discussion. This PR takes only one of them, A1 (grand total), so that the review can focus on the structure. Further cases can be added in later pull requests, each with one case or a small group of cases.

What this PR adds

Path Contents
compliance/query/README.md The case format, the semantics of the expected results, the rules to compare results, and the steps to add a case.
compliance/query/scott/scott.sql The SCOTT schema and its data
compliance/query/scott/scott_model.ossie.yaml An Ossie model over SCOTT with dataset-scoped metrics (#591). It is a real model file, and it passes validation/validate.py.
compliance/query/cases/a01_grand_total/ Case A1: query.ossie.sql, expected.sql, and reference.duckdb.sql.
compliance/README.md Two index lines for portability/ and query/.

Each case is a directory with three files. The part of each SQL file name before .sql gives its dialect; a name without one is standard SQL:

  • query.ossie.sql: the Ossie query, with AGG(). The header (ID, behavior under test, spec sections) is in SQL comments, so a harness can submit the file as it is.
  • expected.sql: the expected result, as one standard SQL query over literals (SELECT * FROM (VALUES ...) AS expected (...)).
  • reference.duckdb.sql: a DuckDB query over the base tables. It is non-normative. It helps to derive expected.sql, and a command in the README shows both results.

An implementation passes a case if it accepts query.ossie.sql against the SCOTT model and returns a result that is equal to the result of expected.sql. One case goes in each directory, so two contributors who add different cases do not change the same file.

Case A1:

-- query.ossie.sql
SELECT AGG(sum_sal) AS sum_sal,
       AGG(emp_count) AS emp_count
FROM scott_model.emp;

-- expected.sql
SELECT *
FROM (VALUES (29025.00, 14)) AS expected (sum_sal, emp_count);

Changes from #628

@justint-db offered to make the "host dialect" wording in the spec clearer. This PR does not change the spec. The README states the rule for the tests only.

Out of scope

Verification

  • With the DuckDB 1.5.6 CLI (not yet in the repo), each command in the README runs as written. For A1, reference.duckdb.sql and expected.sql both give 29025.00 | 14.
  • uv run validation/validate.py compliance/query/scott/scott_model.ossie.yaml passes on current main.

Related Issues

Related: #354, #591, #628, #501, #502.

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, new files only)

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 new 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 cases; it is not a project dependency)
  • 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: no code is copied; the SCOTT data values are the same as in the Apache Calcite tests)

AI disclosure

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

Add compliance/query/ with the shared SCOTT data, an Ossie model over it,
and one case (A1, grand total) for the Relational Query Interface. The
README defines the case format, the semantics of the expected results
(standard SQL), the rules to compare results, and the steps to add a case.

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db christianeu-db changed the title test(compliance): add query compliance test layout with case A1 test(compliance): add initial layer 2 query compliance test framework Oct 23, 2026
@christianeu-db
christianeu-db marked this pull request as ready for review October 23, 2026 18:17
Co-authored-by: Isaac <no-reply@databricks.com>
@justint-db

Copy link
Copy Markdown
Contributor

I think it would be useful to split the Ossie query and the expected results out into their own files. The implementations could check that end-to-end they can accept an Ossie query and output the expected results.

christianeu-db and others added 8 commits October 23, 2026 20:34
…erence files

Each case is now a directory with query.sql (the Ossie query), expected.csv
(the expected result), and reference.sql (the DuckDB query that produces
expected.csv). An implementation can submit query.sql and compare its result
to expected.csv, end to end.

Co-authored-by: Isaac <no-reply@databricks.com>
Rename query.sql to query.ossie.sql and reference.sql to
reference.duckdb.sql, so that the file name shows the dialect.

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

Make emp.sal and emp.comm DOUBLE PRECISION. For AVG over an exact numeric,
the SQL standard leaves the scale of the result implementation-defined, so it
cannot be compared precisely. Replace the absolute 0.01 tolerance with a
relative tolerance of 1e-9 for approximate numerics; exact numerics must be
equal.

Co-authored-by: Isaac <no-reply@databricks.com>
Replace expected.csv with expected.sql, a standard SQL query over literals.
Define the comparison: columns by position, bag semantics, NULL-aware
equality, and row order only for a unique ORDER BY. All expected values are
exact, with no tolerance, so the money columns are DECIMAL(7, 2) again and
the model and case A1 have no AVG.

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

Allow approximate numeric results, compared with a relative tolerance of
1e-9 and an absolute tolerance of 1e-9 near zero, and state that this rule
is provisional. Replace the EXCEPT ALL check with a command that shows the
reference result and the expected result.

Co-authored-by: Isaac <no-reply@databricks.com>
State why the tolerance does not cover AVG over an exact numeric, and that a
case can use AVG over a cast to DOUBLE PRECISION.

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

Copy link
Copy Markdown
Contributor Author

I think it would be useful to split the Ossie query and the expected results out into their own files. The implementations could check that end-to-end they can accept an Ossie query and output the expected results.

Thanks for the feedback! Broke each case into 3 parts: ossie.sql, duck.sql and expected (in .sql)

Comparing results
-----------------

- Columns are matched by position. The column counts MUST be equal. Column

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.

This rule and line 67 can be read as conflicting. Line 67 says column names and order MUST match query.ossie.sql.
This line here say columns are matched by position and names are compared case insensitive. I think the intent is that line 67 constrains the case author, and this line constrain the implementation under test.
If so, could we say that explicitly?

For example, we could change line 67 to "expected.sql MUST use the column names and order of query.ossie.sql", and add "the implementation's own column names are not required to match exactly" here.

As written, an implementation that returns an upper case alias could be judged passing or failing depending on which rule we read.

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.

updated

The file name suffix gives the SQL dialect: `.ossie.sql` for Ossie SQL,
`.duckdb.sql` for DuckDB SQL, and `.sql` for standard SQL (ISO/IEC 9075).

A case passes when an implementation loads the data and the model, runs

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.

Nit: the pass criterion says "loads the data and the model" but doesn't say how names resolve. The schema rule (all relations in a schema named after the model, so scott_model.emp) is explained only in the YAML comment at line 22.
Maybe we could add a sentence or a pointer here, for example "Each dataset is addressable as <model name>.<dataset name>".
That way an implementer reading only the README doesn't resolve scott_model.emp incorrectly.

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.

added a note below

State that expected.sql uses the column names and order of
query.ossie.sql, and that the implementation's own column names are not
required to match exactly. State the name by which the cases refer to
each dataset.

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

Copy link
Copy Markdown
Contributor Author

@jbonofre addressed your comments in the latest commit

@jbonofre

Copy link
Copy Markdown
Member

@christianeu-db awesome! Thanks! I'm doing a new pass 😄

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

Thanks @christianeu-db! This is a great start 😄

The layout and the result rules are clear, and A1 checks out: the 14 salaries add up to 29025.00, the SCOTT data matches the Calcite within-distinct.iq source, and the model passes validate.py.

I think we should do a follow-up about the join recipe.

"It removes join duplicates by primary_key, and then it aggregates" leaves out two steps of Section 9:

  1. Rows whose key is NULL (the null-padded rows of an outer join) must be discarded first. Otherwise dept LEFT JOIN emp gives OPERATIONS a COUNT(*) of 1, where Section 8.1 says 0.
  2. Duplicates are removed within each output group, not across the whole joined result. Otherwise emp JOIN dept ... GROUP BY job keeps dept 30 in only one job group, and CLERK shows fewer than its 3 departments.

Contributors copy expected.sql from the reference output, so the current wording would put wrong values into expected results. Something like:

For joins, it follows Section 9: within each output group, it discards rows whose primary_key is NULL, keeps one row per primary_key, and then aggregates. A group with no remaining rows takes the empty-input value (NULL for SUM, 0 for COUNT).

@christianeu-db

Copy link
Copy Markdown
Contributor Author

Thanks @christianeu-db! This is a great start 😄

The layout and the result rules are clear, and A1 checks out: the 14 salaries add up to 29025.00, the SCOTT data matches the Calcite within-distinct.iq source, and the model passes validate.py.

I think we should do a follow-up about the join recipe.

"It removes join duplicates by primary_key, and then it aggregates" leaves out two steps of Section 9:

  1. Rows whose key is NULL (the null-padded rows of an outer join) must be discarded first. Otherwise dept LEFT JOIN emp gives OPERATIONS a COUNT(*) of 1, where Section 8.1 says 0.
  2. Duplicates are removed within each output group, not across the whole joined result. Otherwise emp JOIN dept ... GROUP BY job keeps dept 30 in only one job group, and CLERK shows fewer than its 3 departments.

Contributors copy expected.sql from the reference output, so the current wording would put wrong values into expected results. Something like:

For joins, it follows Section 9: within each output group, it discards rows whose primary_key is NULL, keeps one row per primary_key, and then aggregates. A group with no remaining rows takes the empty-input value (NULL for SUM, 0 for COUNT).

Thanks for the review. Sounds good - we'll be picking up some join cases in future tests and can clarify the wording there

@christianeu-db
christianeu-db merged commit b627916 into apache:main Oct 30, 2026
6 checks passed
ekut added a commit to Dactopus/dactopus-ossie-clickhouse that referenced this pull request Nov 1, 2026
compliance/query in apache/ossie (since apache/ossie#632) ships the SCOTT
data, a model with dataset metrics and, per case, an AGG() query with its
expected result as standard SQL over literals. tests/test_compliance.py
loads the data through DuckDB into ClickHouse, reads the model as it is,
runs each case as the question it asks and compares by the suite's README:
columns by position, rows as multisets, exact numerics equal, approximate
ones within 1e-9. A case the checkout has and the test does not fails, so
the weekly run on Ossie's main reports a new case. Case A1 passes; SUM
over no rows is NULL and COUNT 0, as the suite demands.

The executor stays a compiler of questions and does not read layer-2 SQL;
docs/design.md records why.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
christianeu-db added a commit to christianeu-db/ossie that referenced this pull request Nov 5, 2026
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>
christianeu-db added a commit to christianeu-db/ossie that referenced this pull request Nov 5, 2026
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>
christianeu-db added a commit to christianeu-db/ossie that referenced this pull request Nov 5, 2026
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>
christianeu-db added a commit to christianeu-db/ossie that referenced this pull request Nov 5, 2026
… 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 added a commit that referenced this pull request Nov 6, 2026
…t cases (#628)

* test(compliance): add relational-semantics query compliance tests

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
(#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 (#501) and view expander (#502).

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

* test(compliance): split relational_semantics.sql into case directories

Move cases A2-A12 and B1-B17 into the case format of #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>

* test(compliance): cast AVG and division results to DOUBLE PRECISION

The README of #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>

* test(compliance): name cases for what they show and add Question lines

@julianhyde suggested an English description of each query (#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>

* docs(compliance): describe the Section 9 recipe of the join reference queries

As @jbonofre suggested on #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>

* test(compliance): use the Ossie expression language in the model and 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 (#640). The model had
  only OSSIE_SQL_2026 entries in dialects.

No expected result changes.

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

* test(compliance): add fan-out risk cases B18-B20 with one-side measures

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>

---------

Co-authored-by: Isaac <no-reply@databricks.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.

3 participants