Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ compliance-test: check-dependencies ## Run portability grader tests
compliance-validate: DEPENDENCIES := $(UV)
compliance-validate: check-dependencies ## Validate compliance models and portability fixtures
@echo "--- Validating compliance fixtures ---"
@$(UV) run --no-project validation/validate.py compliance/portability/m*/*.ossie.yaml compliance/query/scott/scott_model.ossie.yaml
@$(UV) run --no-project validation/validate.py compliance/portability/m*/*.ossie.yaml compliance/query/scott/scott_model.ossie.yaml compliance/wide_table/retail/retail_model.ossie.yaml
@echo "--- Compliance fixture validation complete ---"

.PHONY: compliance-query
Expand Down
2 changes: 2 additions & 0 deletions compliance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ This is for compliance tests
model survives a round trip through each converter.
- [`query/`](query/): query test cases for the
[Relational Query Interface](../core-spec/relational_semantics.md).
- [`wide_table/`](wide_table/): query test cases for the
[Wide Table Query Interface](../core-spec/wide_table_semantics.md).
104 changes: 104 additions & 0 deletions compliance/wide_table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

Wide table compliance tests
===========================

Compliance tests for the
[Wide Table Query Interface](../../core-spec/wide_table_semantics.md)
(Layer 3). All cases use the same data and Ossie model. The data and the
expected results come from the examples of the specification: Section 1.3,
Section 5.2, Section 6.1, and Appendix B.

The key words MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY are to be
interpreted as described in BCP 14
([RFC 2119](https://www.rfc-editor.org/rfc/rfc2119),
[RFC 8174](https://www.rfc-editor.org/rfc/rfc8174)) when they appear in
uppercase.

Layout
------

| Path | Contents |
|------|----------|
| [`retail/retail.sql`](retail/retail.sql) | Schema and data: customers, orders, returns, visits, and tickets |
| [`retail/retail_model.ossie.yaml`](retail/retail_model.ossie.yaml) | Ossie model with relationships and metrics |
| `cases/<case>/query.json` | Query under test, in the JSON binding of Section 3.7 |
| `cases/<case>/expected.json` | Expected result or error |

Cases `a*` return rows. Cases `e*` raise an error; they follow the order of
the table in Section 8, and `e20` and `e21` test that order.

A case passes when an implementation loads the data and the model, submits
`query.json`, and either returns a result equal to the expected rows (see
"Comparing results") or raises the expected error.

Case files
----------

`query.json` is the query as a consumer submits it. It has only the parts of
Section 3.2.

`expected.json` describes the case and its result:

- `title`: what the case shows.
- `question`: what the query asks, in English. It helps a reader; the query is
the ground truth.
- `behavior`: the rule under test, and why the result has its values.
- `spec`: the sections of the specification that define the result.
- `columns` and `rows`: the expected result, with the output names of Section
3.3 in query order. Or `error`: the code from Section 8 that the engine
MUST raise.

```json
{
"title": "Groups come from the metric's dataset",
"question": "What is the order amount by customer region?",
"behavior": "One branch from orders. NORTH has no orders, so it is not a group.",
"spec": ["5.4", "6.1"],
"columns": ["region", "total_revenue"],
"rows": [
["EAST", 350],
["WEST", 300]
]
}
```

For codes 13, 14, and 16, Section 8 also requires the error to identify the
dimension or the filter, and a metric or the anchor that does not reach its
dataset. `behavior` names them. How an engine reports them depends on its
binding, so the cases check only the code.

Result semantics
----------------

The rules of [`../query/README.md`](../query/README.md), "Result semantics",
apply. For example, `SUM` over no rows is NULL and `COUNT(*)` over no rows is
0, which gives the empty-input values of Section 5.2.

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

Results are compared as in [`../query/README.md`](../query/README.md),
"Comparing results". Rows have no defined order (Section 3.6). In
`expected.json`:

- A JSON number without a fraction or an exponent is an exact numeric. Any
other JSON number is an approximate numeric.
- A JSON `null` is SQL NULL.
12 changes: 12 additions & 0 deletions compliance/wide_table/cases/a01_shared_dimension/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "Two metrics share a dimension",
"question": "What are the order and return amounts by customer region?",
"behavior": "Each metric is a branch from its own dataset to customers. The keys are the regions of either branch; a region missing from a branch takes the empty-input value of SUM, NULL.",
Comment on lines +2 to +4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These details probably belong alongside the query or test setup. As a first step, we could capture them in READMEs in the test folders, then eventually migrate them into comments in the .ost test cases.

"spec": ["1.3", "5.4", "5.5"],
"columns": ["region", "total_revenue", "total_returns"],
"rows": [
["EAST", 350, 25],
["WEST", 300, null],
["NORTH", null, 10]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a01_shared_dimension/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue", "returns.total_returns"]
}
12 changes: 12 additions & 0 deletions compliance/wide_table/cases/a02_count_empty_input/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "A missing branch row takes the empty-input value of COUNT(*)",
"question": "What is the order amount and the number of returns by customer region?",
"behavior": "WEST has orders and no returns. Its return_count is the empty-input value of COUNT(*), 0, not NULL.",
"spec": ["5.2", "5.5", "B.1"],
"columns": ["region", "total_revenue", "return_count"],
"rows": [
["EAST", 350, 1],
["WEST", 300, 0],
["NORTH", null, 1]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a02_count_empty_input/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue", "returns.return_count"]
}
12 changes: 12 additions & 0 deletions compliance/wide_table/cases/a03_three_branches/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "Three branches give each key once",
"question": "What are the order amount, return amount, and number of visits by customer region?",
"behavior": "Each branch supplies some regions. NORTH is in the returns and visits branches but not in the orders branch, and appears once.",
"spec": ["5.5", "B.2"],
"columns": ["region", "total_revenue", "total_returns", "visit_count"],
"rows": [
["EAST", 350, 25, 0],
["WEST", 300, null, 1],
["NORTH", null, 10, 2]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a03_three_branches/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue", "returns.total_returns", "visits.visit_count"]
}
11 changes: 11 additions & 0 deletions compliance/wide_table/cases/a04_filter_on_dimension/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "A filter on the dimension dataset applies to every branch",
"question": "What are the order and return amounts by customer region, outside EAST?",
"behavior": "Both metrics reach customers, so the filter applies to both branches. The filter removes groups and adds none.",
"spec": ["3.4", "5.3", "6", "B.1"],
"columns": ["region", "total_revenue", "total_returns"],
"rows": [
["WEST", 300, null],
["NORTH", null, 10]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue", "returns.total_returns"],
"filter": "customers.region <> 'EAST'"
}
11 changes: 11 additions & 0 deletions compliance/wide_table/cases/a05_groups_from_orders/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Groups come from the metric's dataset",
"question": "What is the order amount by customer region?",
"behavior": "One branch from orders. NORTH has no orders, so it is not a group.",
"spec": ["5.4", "6.1"],
"columns": ["region", "total_revenue"],
"rows": [
["EAST", 350],
["WEST", 300]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a05_groups_from_orders/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue"]
}
11 changes: 11 additions & 0 deletions compliance/wide_table/cases/a06_groups_from_returns/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Another metric gives other groups",
"question": "What is the return amount by customer region?",
"behavior": "One branch from returns. WEST has no returns, so it is not a group.",
"spec": ["5.4", "6.1"],
"columns": ["region", "total_returns"],
"rows": [
["EAST", 25],
["NORTH", 10]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["customers.region"],
"metrics": ["returns.total_returns"]
}
12 changes: 12 additions & 0 deletions compliance/wide_table/cases/a07_dimension_only/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "A query without metrics uses an anchor",
"question": "Which customer regions are there?",
"behavior": "The anchor is customers, the dataset of the only dimension. The result has its distinct regions.",
"spec": ["3.2", "5.6", "6.1"],
"columns": ["region"],
"rows": [
["EAST"],
["WEST"],
["NORTH"]
]
}
3 changes: 3 additions & 0 deletions compliance/wide_table/cases/a07_dimension_only/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dimensions": ["customers.region"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "Each component of a model-scoped metric aggregates its own dataset",
"question": "What is the order amount per customer?",
"behavior": "The metric has a component on orders and one on customers. Each is a branch of its own, so the customer count includes C4, which has no orders: 650 / 4.",
"spec": ["5.2", "5.5"],
"columns": ["revenue_per_customer"],
"rows": [
[162.5]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"metrics": ["revenue_per_customer"]
}
11 changes: 11 additions & 0 deletions compliance/wide_table/cases/a09_aliases/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Aliases name the output columns",
"question": "What is the order amount by customer region?",
"behavior": "The object form gives each entry an alias, and the alias is its output name.",
"spec": ["3.3", "3.6", "3.7"],
"columns": ["area", "revenue"],
"rows": [
["EAST", 350],
["WEST", 300]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a09_aliases/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": [{"field": "customers.region", "alias": "area"}],
"metrics": [{"metric": "orders.total_revenue", "alias": "revenue"}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "A filter on a dataset the metric reaches",
"question": "What is the order amount of customers in EAST?",
"behavior": "The branch from orders joins customers for the filter. Without dimensions, the result has one row.",
"spec": ["3.4", "5.4", "B.5"],
"columns": ["total_revenue"],
"rows": [
[350]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["orders.total_revenue"],
"filter": "customers.region = 'EAST'"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "A filter on the metric's own dataset",
"question": "What is the amount of orders over 100 by customer region?",
"behavior": "The filter removes O1 and O3 before aggregation.",
"spec": ["3.4", "5.4", "B.5"],
"columns": ["region", "total_revenue"],
"rows": [
["EAST", 200],
["WEST", 300]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue"],
"filter": "orders.amount > 100"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "The anchor is the dimension dataset that reaches the others",
"question": "Which orders over 100 are there, with the region of their customer?",
"behavior": "orders reaches customers, and customers does not reach orders, so the anchor is orders.",
"spec": ["5.6", "B.5"],
"columns": ["order_id", "region"],
"rows": [
["O2", "EAST"],
["O4", "WEST"]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["orders.order_id", "customers.region"],
"filter": "orders.amount > 100"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"title": "A filter that removes every row leaves no groups",
"question": "What is the order amount by customer region, when no order is kept?",
"behavior": "The branch has no rows, so there are no keys and no rows.",
"spec": ["3.4", "5.5", "B.5"],
"columns": ["region", "total_revenue"],
"rows": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dimensions": ["customers.region"],
"metrics": ["orders.total_revenue"],
"filter": "FALSE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "Without dimensions, the result has one row",
"question": "What is the order amount, when no order is kept?",
"behavior": "The only key is the empty tuple. The value is the empty-input value of SUM, NULL.",
"spec": ["3.6", "5.5", "B.5"],
"columns": ["total_revenue"],
"rows": [
[null]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["orders.total_revenue"],
"filter": "FALSE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "A filter without a dataset applies to unconnected metrics",
"question": "What are the order amount and the number of tickets, when no row is kept?",
"behavior": "FALSE reads no dataset, so it needs no path. Each metric takes its empty-input value: NULL for SUM, 0 for COUNT(*).",
"spec": ["3.4", "5.3", "B.4"],
"columns": ["total_revenue", "ticket_count"],
"rows": [
[null, 0]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["orders.total_revenue", "tickets.ticket_count"],
"filter": "FALSE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "An unsupported part is malformed",
"question": "What is the order amount, limited to 10 rows?",
"behavior": "limit is not a part of this version. The engine rejects it rather than ignore it.",
"spec": ["3.5", "3.7", "8"],
"error": "E_INVALID_QUERY"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["orders.total_revenue"],
"limit": 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "A null value is malformed",
"question": "What is the order amount, with a null filter?",
"behavior": "The JSON binding treats null values as malformed.",
"spec": ["3.7", "8"],
"error": "E_INVALID_QUERY"
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/e02_invalid_query_null/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["orders.total_revenue"],
"filter": null
}
Loading
Loading