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 @@ -178,7 +178,7 @@ compliance-validate: DEPENDENCIES := $(UV)
compliance-validate: ## Validate compliance models and portability fixtures
$(call check_deps,$(DEPENDENCIES))
@echo "--- Validating compliance fixtures ---"
@$(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
@$(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 compliance/wide_table/stores/stores_model.ossie.yaml compliance/wide_table/stores/stores_ambiguous_model.ossie.yaml
@echo "--- Compliance fixture validation complete ---"

.PHONY: compliance-query
Expand Down
48 changes: 38 additions & 10 deletions compliance/wide_table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ 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.
(Layer 3). Cases use one of the fixtures below. 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
Expand All @@ -37,17 +37,44 @@ 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 |
| [`retail/retail.sql`](retail/retail.sql) | Schema and data: customers, orders, returns, visits, and tickets (Appendix B.1, B.2, B.4, B.5) |
| [`retail/retail_model.ossie.yaml`](retail/retail_model.ossie.yaml) | Ossie model over `retail.sql` |
| [`stores/stores.sql`](stores/stores.sql) | Schema and data: store_sales, store_returns, item, date_dim, store, and customers (Appendix B.3; unmatched home rows) |
| [`stores/stores_model.ossie.yaml`](stores/stores_model.ossie.yaml) | Ossie model over `stores.sql` with one path from `store_sales` to `date_dim` |
| [`stores/stores_ambiguous_model.ossie.yaml`](stores/stores_ambiguous_model.ossie.yaml) | Same as `stores_model`, plus `store` to `date_dim` through `closing_date_id` |
| `cases/<case>/query.json` | Query under test, in the JSON binding of Section 3.7 |
| `cases/<case>/expected.json` | Expected result or error |
| `cases/<case>/expected.json` | Expected result or error, and which fixture to load |

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.
the table in Section 8 where applicable, and `e20` and `e21` test that order.
`e22` and `e23` cover `E_AMBIGUOUS_PATH` (Section 8, row 17).

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.
A case passes when an implementation loads the fixture named in
`expected.json`, submits `query.json`, and either returns a result equal to
the expected rows (see "Comparing results") or raises the expected error.

Fixtures
--------

Each `expected.json` may set `fixture` to one of:

| `fixture` | SQL | Model |
|-----------|-----|-------|
| `retail` (default when omitted) | [`retail/retail.sql`](retail/retail.sql) | [`retail/retail_model.ossie.yaml`](retail/retail_model.ossie.yaml) |
| `stores` | [`stores/stores.sql`](stores/stores.sql) | [`stores/stores_model.ossie.yaml`](stores/stores_model.ossie.yaml) |
| `stores_ambiguous` | [`stores/stores.sql`](stores/stores.sql) | [`stores/stores_ambiguous_model.ossie.yaml`](stores/stores_ambiguous_model.ossie.yaml) |

`retail` matches Appendix B.1–B.2 and B.4–B.5: every order, return, and visit
matches a customer, so no NULL groups arise from unmatched home rows.

`stores` matches Appendix B.3 without the closing-date relationship. Some
`store_sales` rows have a NULL `customer_id`, and one customer has a NULL
`region`, so a `LEFT JOIN` places amounts in a NULL group (Sections 4 and 5.5,
S1). An `INNER JOIN` would drop those rows.

`stores_ambiguous` adds `store` to `date_dim` through `closing_date_id`, so
`store_sales` has two paths to `date_dim`. Cases `e22` and `e23` use this
fixture; `a19` and `a20` are the same queries on `stores` and succeed.

Case files
----------
Expand All @@ -57,6 +84,7 @@ Section 3.2.

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

- `fixture`: which SQL and model to load (see above). Omit for `retail`.
- `title`: what the case shows.
- `question`: what the query asks, in English. It helps a reader; the query is
the ground truth.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"fixture": "stores",
"title": "Two fact metrics share item and date dimensions",
"question": "What are the sales and return amounts by item brand and year?",
"behavior": "store_sales and store_returns each form a branch to item and date_dim. Keys are the brand and year pairs from either branch. Acme in 2024 has sales and no returns, so total_returns is NULL. Appendix B.3 shared dimensions.",
"spec": ["4", "5.4", "5.5", "B.3"],
"columns": ["brand", "year", "total_sales", "total_returns"],
"rows": [
["Acme", 2023, 125, 10],
["Acme", 2024, 200, null],
["Beta", 2024, 90, 5]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["item.brand", "date_dim.year"],
"metrics": ["store_sales.total_sales", "store_returns.total_returns"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"fixture": "stores",
"title": "Unmatched home rows and NULL dimension keys form a NULL group",
"question": "What is the sales amount by customer region?",
"behavior": "The branch LEFT JOINs customers from store_sales. SS4 has no customer, and C3 has a NULL region; both place their amounts in the NULL region group (25 + 40). An INNER JOIN would drop them. S1; Sections 4 and 5.5.",
"spec": ["4", "5.4", "5.5"],
"columns": ["region", "total_sales"],
"rows": [
["EAST", 150],
["WEST", 200],
[null, 65]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["customers.region"],
"metrics": ["store_sales.total_sales"]
}
12 changes: 12 additions & 0 deletions compliance/wide_table/cases/a18_anchor_with_metric/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fixture": "stores",
"title": "A metric makes an otherwise unanchored query valid",
"question": "What is the sales amount by item brand and store state?",
"behavior": "Without a metric, item and store cannot reach each other (e25). store_sales reaches both, so the query is valid. Appendix B.3.",
"spec": ["5.3", "5.6", "B.3"],
"columns": ["brand", "state", "total_sales"],
"rows": [
["Acme", "CA", 325],
["Beta", "NY", 90]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a18_anchor_with_metric/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["item.brand", "store.state"],
"metrics": ["store_sales.total_sales"]
}
12 changes: 12 additions & 0 deletions compliance/wide_table/cases/a19_sales_by_year/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fixture": "stores",
"title": "One path from store_sales to date_dim",
"question": "What is the sales amount by year?",
"behavior": "store_sales reaches date_dim only through sale_date_id, so the query is valid. The same query against stores_ambiguous raises E_AMBIGUOUS_PATH (e22).",
"spec": ["4", "5.4", "B.3"],
"columns": ["year", "total_sales"],
"rows": [
[2023, 125],
[2024, 290]
]
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/a19_sales_by_year/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["date_dim.year"],
"metrics": ["store_sales.total_sales"]
}
11 changes: 11 additions & 0 deletions compliance/wide_table/cases/a20_filter_on_sale_year/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"fixture": "stores",
"title": "A filter on date_dim with one path",
"question": "What is the total sales amount for year 2024?",
"behavior": "store_sales reaches date_dim only through sale_date_id, so the filter applies. Sales in 2024 are 200 + 50 + 40 = 290. The same query against stores_ambiguous raises E_AMBIGUOUS_PATH (e23).",
"spec": ["4", "5.3", "5.4", "B.3"],
"columns": ["total_sales"],
"rows": [
[290]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["store_sales.total_sales"],
"filter": "date_dim.year = 2024"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fixture": "stores_ambiguous",
"title": "Two paths from store_sales to date_dim",
"question": "What is the sales amount by year?",
"behavior": "store_sales reaches date_dim through sale_date_id and through store then closing_date_id. The engine must raise E_AMBIGUOUS_PATH even though one path is shorter. Appendix B.3.",
"spec": ["4", "8", "B.3"],
"error": "E_AMBIGUOUS_PATH"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["date_dim.year"],
"metrics": ["store_sales.total_sales"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fixture": "stores_ambiguous",
"title": "A filter on date_dim is ambiguous from store_sales",
"question": "What is the total sales amount for year 2024?",
"behavior": "The filter's dataset is date_dim. store_sales has two paths to it, so the join tree is ambiguous. Appendix B.3.",
"spec": ["4", "5.3", "8", "B.3"],
"error": "E_AMBIGUOUS_PATH"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"metrics": ["store_sales.total_sales"],
"filter": "date_dim.year = 2024"
}
8 changes: 8 additions & 0 deletions compliance/wide_table/cases/e24_no_path_stores/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fixture": "stores",
"title": "customers cannot reach item",
"question": "How many customers are there per item brand?",
"behavior": "Relationships are many-to-one from store_sales to customers and to item. customers cannot reach item. The error names item.brand and customers.customer_count. Appendix B.3.",
"spec": ["4", "5.3", "8", "B.3"],
"error": "E_NO_PATH"
}
4 changes: 4 additions & 0 deletions compliance/wide_table/cases/e24_no_path_stores/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dimensions": ["item.brand"],
"metrics": ["customers.customer_count"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fixture": "stores",
"title": "item and store cannot reach each other",
"question": "Which pairs of item brand and store state are there?",
"behavior": "Neither item nor store reaches the other, so there is no anchor. Adding store_sales.total_sales makes the query valid (a18). Appendix B.3.",
"spec": ["5.6", "8", "B.3"],
"error": "E_NO_ANCHOR"
}
3 changes: 3 additions & 0 deletions compliance/wide_table/cases/e25_no_anchor_stores/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dimensions": ["item.brand", "store.state"]
}
96 changes: 96 additions & 0 deletions compliance/wide_table/stores/stores.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-- 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.

-- ============================================================================
-- Data: store_sales, store_returns, item, date_dim, store, and customers
--
-- Shared input for the Appendix B.3 and unmatched-home-row cases under
-- ../cases/. Load this file before a stores case runs. Do not change the
-- values: the expected results depend on them.
--
-- SS4 has no customer; C3 has a NULL region (NULL groups / S1).
-- stores_ambiguous_model adds store → date_dim via closing_date_id.
-- ============================================================================

DROP SCHEMA IF EXISTS stores CASCADE;
CREATE SCHEMA stores;

CREATE TABLE stores.date_dim (
date_id VARCHAR NOT NULL PRIMARY KEY,
year INTEGER NOT NULL
);

INSERT INTO stores.date_dim VALUES
('D2023', 2023),
('D2024a', 2024),
('D2024b', 2024);

CREATE TABLE stores.item (
item_id VARCHAR NOT NULL PRIMARY KEY,
brand VARCHAR NOT NULL
);

INSERT INTO stores.item VALUES
('I1', 'Acme'),
('I2', 'Beta');

CREATE TABLE stores.store (
store_id VARCHAR NOT NULL PRIMARY KEY,
state VARCHAR NOT NULL,
closing_date_id VARCHAR NOT NULL
);

INSERT INTO stores.store VALUES
('S1', 'CA', 'D2024b'),
('S2', 'NY', 'D2024a');

CREATE TABLE stores.customers (
customer_id VARCHAR NOT NULL PRIMARY KEY,
region VARCHAR
);

INSERT INTO stores.customers VALUES
('C1', 'EAST'),
('C2', 'WEST'),
('C3', NULL);

CREATE TABLE stores.store_sales (
sale_id VARCHAR NOT NULL PRIMARY KEY,
item_id VARCHAR NOT NULL,
sale_date_id VARCHAR NOT NULL,
store_id VARCHAR NOT NULL,
customer_id VARCHAR,
sales_amount INTEGER NOT NULL
);

INSERT INTO stores.store_sales VALUES
('SS1', 'I1', 'D2023', 'S1', 'C1', 100),
('SS2', 'I1', 'D2024a', 'S1', 'C2', 200),
('SS3', 'I2', 'D2024a', 'S2', 'C1', 50),
('SS4', 'I1', 'D2023', 'S1', NULL, 25),
('SS5', 'I2', 'D2024a', 'S2', 'C3', 40);

CREATE TABLE stores.store_returns (
return_id VARCHAR NOT NULL PRIMARY KEY,
item_id VARCHAR NOT NULL,
return_date_id VARCHAR NOT NULL,
return_amount INTEGER NOT NULL
);

INSERT INTO stores.store_returns VALUES
('SR1', 'I1', 'D2023', 10),
('SR2', 'I2', 'D2024a', 5);
Loading
Loading