Repository navigation
test(compliance): add initial layer 2 query compliance test framework - #632
Conversation
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>
Co-authored-by: Isaac <no-reply@databricks.com>
|
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. |
…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>
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 |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
d725491 to
3f12241
Compare
|
@jbonofre addressed your comments in the latest commit |
|
@christianeu-db awesome! Thanks! I'm doing a new pass 😄 |
jbonofre
left a comment
There was a problem hiding this comment.
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:
- Rows whose key is NULL (the null-padded rows of an outer join) must be discarded first. Otherwise
dept LEFT JOIN empgives OPERATIONS aCOUNT(*)of 1, where Section 8.1 says 0. - Duplicates are removed within each output group, not across the whole joined result. Otherwise
emp JOIN dept ... GROUP BY jobkeeps 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_keyis NULL, keeps one row perprimary_key, and then aggregates. A group with no remaining rows takes the empty-input value (NULLforSUM,0forCOUNT).
Thanks for the review. Sounds good - we'll be picking up some join cases in future tests and can clarify the wording there |
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>
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>
… 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>
…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>
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
compliance/query/README.mdcompliance/query/scott/scott.sqlcompliance/query/scott/scott_model.ossie.yamlvalidation/validate.py.compliance/query/cases/a01_grand_total/query.ossie.sql,expected.sql, andreference.duckdb.sql.compliance/README.mdportability/andquery/.Each case is a directory with three files. The part of each SQL file name before
.sqlgives its dialect; a name without one is standard SQL:query.ossie.sql: the Ossie query, withAGG(). 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 deriveexpected.sql, and a command in the README shows both results.An implementation passes a case if it accepts
query.ossie.sqlagainst the SCOTT model and returns a result that is equal to the result ofexpected.sql. One case goes in each directory, so two contributors who add different cases do not change the same file.Case A1:
Changes from #628
validate.pycan check it.bonustable is removed. No case uses it.@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
.ost, a file format for idempotent test scripts #501) and a view expander (View expander #502). When those are available, each case can become an.osttest.Verification
reference.duckdb.sqlandexpected.sqlboth give29025.00 | 14.uv run validation/validate.py compliance/query/scott/scott_model.ossie.yamlpasses on currentmain.Related Issues
Related: #354, #591, #628, #501, #502.
Checklist
Specification
core-spec/and follow the existing structure (N/A: no spec change)Ontology
ontology/are consistent with spec changes (N/A)Converters
Validation
validation/are updated if the spec changed (N/A)validate.py)Documentation
docs/is updated to reflect any user-facing changes (N/A)compliance/query/README.md)CONTRIBUTING.mdis updated if the contribution process changed (N/A)Examples
examples/are added or updated for any new spec constructs (N/A)Tests
pytest/ CI green) (no code change; waiting for CI)Compliance
NOTICEand/orLICENSEhave 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.