From 3d07017c3b852a9279038a681fb6284d9d83d8e9 Mon Sep 17 00:00:00 2001 From: prithvi Date: Sun, 15 Nov 2026 02:19:35 +0530 Subject: [PATCH] feat(compliance): add Layer 3 B.3 stores fixture and E_AMBIGUOUS_PATH cases Signed-off-by: prithvi --- Makefile | 2 +- compliance/wide_table/README.md | 48 ++++- .../expected.json | 13 ++ .../a16_shared_dimensions_stores/query.json | 4 + .../expected.json | 13 ++ .../a17_unmatched_home_null_group/query.json | 4 + .../a18_anchor_with_metric/expected.json | 12 ++ .../cases/a18_anchor_with_metric/query.json | 4 + .../cases/a19_sales_by_year/expected.json | 12 ++ .../cases/a19_sales_by_year/query.json | 4 + .../a20_filter_on_sale_year/expected.json | 11 ++ .../cases/a20_filter_on_sale_year/query.json | 4 + .../expected.json | 8 + .../e22_ambiguous_path_dimension/query.json | 4 + .../e23_ambiguous_path_filter/expected.json | 8 + .../e23_ambiguous_path_filter/query.json | 4 + .../cases/e24_no_path_stores/expected.json | 8 + .../cases/e24_no_path_stores/query.json | 4 + .../cases/e25_no_anchor_stores/expected.json | 8 + .../cases/e25_no_anchor_stores/query.json | 3 + compliance/wide_table/stores/stores.sql | 96 +++++++++ .../stores/stores_ambiguous_model.ossie.yaml | 186 ++++++++++++++++++ .../wide_table/stores/stores_model.ossie.yaml | 181 +++++++++++++++++ 23 files changed, 630 insertions(+), 11 deletions(-) create mode 100644 compliance/wide_table/cases/a16_shared_dimensions_stores/expected.json create mode 100644 compliance/wide_table/cases/a16_shared_dimensions_stores/query.json create mode 100644 compliance/wide_table/cases/a17_unmatched_home_null_group/expected.json create mode 100644 compliance/wide_table/cases/a17_unmatched_home_null_group/query.json create mode 100644 compliance/wide_table/cases/a18_anchor_with_metric/expected.json create mode 100644 compliance/wide_table/cases/a18_anchor_with_metric/query.json create mode 100644 compliance/wide_table/cases/a19_sales_by_year/expected.json create mode 100644 compliance/wide_table/cases/a19_sales_by_year/query.json create mode 100644 compliance/wide_table/cases/a20_filter_on_sale_year/expected.json create mode 100644 compliance/wide_table/cases/a20_filter_on_sale_year/query.json create mode 100644 compliance/wide_table/cases/e22_ambiguous_path_dimension/expected.json create mode 100644 compliance/wide_table/cases/e22_ambiguous_path_dimension/query.json create mode 100644 compliance/wide_table/cases/e23_ambiguous_path_filter/expected.json create mode 100644 compliance/wide_table/cases/e23_ambiguous_path_filter/query.json create mode 100644 compliance/wide_table/cases/e24_no_path_stores/expected.json create mode 100644 compliance/wide_table/cases/e24_no_path_stores/query.json create mode 100644 compliance/wide_table/cases/e25_no_anchor_stores/expected.json create mode 100644 compliance/wide_table/cases/e25_no_anchor_stores/query.json create mode 100644 compliance/wide_table/stores/stores.sql create mode 100644 compliance/wide_table/stores/stores_ambiguous_model.ossie.yaml create mode 100644 compliance/wide_table/stores/stores_model.ossie.yaml diff --git a/Makefile b/Makefile index d29ddfb0..54a43b93 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/compliance/wide_table/README.md b/compliance/wide_table/README.md index dbf0208e..fc105136 100644 --- a/compliance/wide_table/README.md +++ b/compliance/wide_table/README.md @@ -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 @@ -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//query.json` | Query under test, in the JSON binding of Section 3.7 | -| `cases//expected.json` | Expected result or error | +| `cases//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 ---------- @@ -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. diff --git a/compliance/wide_table/cases/a16_shared_dimensions_stores/expected.json b/compliance/wide_table/cases/a16_shared_dimensions_stores/expected.json new file mode 100644 index 00000000..11f3b196 --- /dev/null +++ b/compliance/wide_table/cases/a16_shared_dimensions_stores/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a16_shared_dimensions_stores/query.json b/compliance/wide_table/cases/a16_shared_dimensions_stores/query.json new file mode 100644 index 00000000..46d14aa9 --- /dev/null +++ b/compliance/wide_table/cases/a16_shared_dimensions_stores/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["item.brand", "date_dim.year"], + "metrics": ["store_sales.total_sales", "store_returns.total_returns"] +} diff --git a/compliance/wide_table/cases/a17_unmatched_home_null_group/expected.json b/compliance/wide_table/cases/a17_unmatched_home_null_group/expected.json new file mode 100644 index 00000000..1fa2c46f --- /dev/null +++ b/compliance/wide_table/cases/a17_unmatched_home_null_group/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a17_unmatched_home_null_group/query.json b/compliance/wide_table/cases/a17_unmatched_home_null_group/query.json new file mode 100644 index 00000000..c7a346cb --- /dev/null +++ b/compliance/wide_table/cases/a17_unmatched_home_null_group/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["store_sales.total_sales"] +} diff --git a/compliance/wide_table/cases/a18_anchor_with_metric/expected.json b/compliance/wide_table/cases/a18_anchor_with_metric/expected.json new file mode 100644 index 00000000..9d27781b --- /dev/null +++ b/compliance/wide_table/cases/a18_anchor_with_metric/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a18_anchor_with_metric/query.json b/compliance/wide_table/cases/a18_anchor_with_metric/query.json new file mode 100644 index 00000000..4014ac8d --- /dev/null +++ b/compliance/wide_table/cases/a18_anchor_with_metric/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["item.brand", "store.state"], + "metrics": ["store_sales.total_sales"] +} diff --git a/compliance/wide_table/cases/a19_sales_by_year/expected.json b/compliance/wide_table/cases/a19_sales_by_year/expected.json new file mode 100644 index 00000000..ff974ea4 --- /dev/null +++ b/compliance/wide_table/cases/a19_sales_by_year/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a19_sales_by_year/query.json b/compliance/wide_table/cases/a19_sales_by_year/query.json new file mode 100644 index 00000000..21dfbcf8 --- /dev/null +++ b/compliance/wide_table/cases/a19_sales_by_year/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["date_dim.year"], + "metrics": ["store_sales.total_sales"] +} diff --git a/compliance/wide_table/cases/a20_filter_on_sale_year/expected.json b/compliance/wide_table/cases/a20_filter_on_sale_year/expected.json new file mode 100644 index 00000000..42c1e699 --- /dev/null +++ b/compliance/wide_table/cases/a20_filter_on_sale_year/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a20_filter_on_sale_year/query.json b/compliance/wide_table/cases/a20_filter_on_sale_year/query.json new file mode 100644 index 00000000..a2a9814d --- /dev/null +++ b/compliance/wide_table/cases/a20_filter_on_sale_year/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["store_sales.total_sales"], + "filter": "date_dim.year = 2024" +} diff --git a/compliance/wide_table/cases/e22_ambiguous_path_dimension/expected.json b/compliance/wide_table/cases/e22_ambiguous_path_dimension/expected.json new file mode 100644 index 00000000..fafb2099 --- /dev/null +++ b/compliance/wide_table/cases/e22_ambiguous_path_dimension/expected.json @@ -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" +} diff --git a/compliance/wide_table/cases/e22_ambiguous_path_dimension/query.json b/compliance/wide_table/cases/e22_ambiguous_path_dimension/query.json new file mode 100644 index 00000000..21dfbcf8 --- /dev/null +++ b/compliance/wide_table/cases/e22_ambiguous_path_dimension/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["date_dim.year"], + "metrics": ["store_sales.total_sales"] +} diff --git a/compliance/wide_table/cases/e23_ambiguous_path_filter/expected.json b/compliance/wide_table/cases/e23_ambiguous_path_filter/expected.json new file mode 100644 index 00000000..1383d686 --- /dev/null +++ b/compliance/wide_table/cases/e23_ambiguous_path_filter/expected.json @@ -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" +} diff --git a/compliance/wide_table/cases/e23_ambiguous_path_filter/query.json b/compliance/wide_table/cases/e23_ambiguous_path_filter/query.json new file mode 100644 index 00000000..a2a9814d --- /dev/null +++ b/compliance/wide_table/cases/e23_ambiguous_path_filter/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["store_sales.total_sales"], + "filter": "date_dim.year = 2024" +} diff --git a/compliance/wide_table/cases/e24_no_path_stores/expected.json b/compliance/wide_table/cases/e24_no_path_stores/expected.json new file mode 100644 index 00000000..099ff885 --- /dev/null +++ b/compliance/wide_table/cases/e24_no_path_stores/expected.json @@ -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" +} diff --git a/compliance/wide_table/cases/e24_no_path_stores/query.json b/compliance/wide_table/cases/e24_no_path_stores/query.json new file mode 100644 index 00000000..41453f82 --- /dev/null +++ b/compliance/wide_table/cases/e24_no_path_stores/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["item.brand"], + "metrics": ["customers.customer_count"] +} diff --git a/compliance/wide_table/cases/e25_no_anchor_stores/expected.json b/compliance/wide_table/cases/e25_no_anchor_stores/expected.json new file mode 100644 index 00000000..25296be9 --- /dev/null +++ b/compliance/wide_table/cases/e25_no_anchor_stores/expected.json @@ -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" +} diff --git a/compliance/wide_table/cases/e25_no_anchor_stores/query.json b/compliance/wide_table/cases/e25_no_anchor_stores/query.json new file mode 100644 index 00000000..c63aba8c --- /dev/null +++ b/compliance/wide_table/cases/e25_no_anchor_stores/query.json @@ -0,0 +1,3 @@ +{ + "dimensions": ["item.brand", "store.state"] +} diff --git a/compliance/wide_table/stores/stores.sql b/compliance/wide_table/stores/stores.sql new file mode 100644 index 00000000..831151d0 --- /dev/null +++ b/compliance/wide_table/stores/stores.sql @@ -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); diff --git a/compliance/wide_table/stores/stores_ambiguous_model.ossie.yaml b/compliance/wide_table/stores/stores_ambiguous_model.ossie.yaml new file mode 100644 index 00000000..12b115ee --- /dev/null +++ b/compliance/wide_table/stores/stores_ambiguous_model.ossie.yaml @@ -0,0 +1,186 @@ +# 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. + +# yaml-language-server: $schema=../../../core-spec/ossie-schema.json +# +# stores_model plus store → date_dim through closing_date_id, so store_sales +# has two paths to date_dim (Appendix B.3 / E_AMBIGUOUS_PATH). + +version: 0.3.0.dev0 +name: stores_ambiguous +description: Store sales with two paths from store_sales to date_dim +datasets: + - name: date_dim + source: stores.date_dim + primary_key: [date_id] + fields: + - name: date_id + datatype: String + expression: + sql: date_id + - name: year + datatype: Integer + expression: + sql: year + + - name: item + source: stores.item + primary_key: [item_id] + fields: + - name: item_id + datatype: String + expression: + sql: item_id + - name: brand + datatype: String + expression: + sql: brand + + - name: store + source: stores.store + primary_key: [store_id] + fields: + - name: store_id + datatype: String + expression: + sql: store_id + - name: state + datatype: String + expression: + sql: state + - name: closing_date_id + datatype: String + expression: + sql: closing_date_id + + - name: customers + source: stores.customers + primary_key: [customer_id] + fields: + - name: customer_id + datatype: String + expression: + sql: customer_id + - name: region + datatype: String + expression: + sql: region + metrics: + - name: customer_count + description: Number of customers + datatype: Integer + expression: + sql: COUNT(*) + + - name: store_sales + source: stores.store_sales + primary_key: [sale_id] + fields: + - name: sale_id + datatype: String + expression: + sql: sale_id + - name: item_id + datatype: String + expression: + sql: item_id + - name: sale_date_id + datatype: String + expression: + sql: sale_date_id + - name: store_id + datatype: String + expression: + sql: store_id + - name: customer_id + datatype: String + expression: + sql: customer_id + - name: sales_amount + datatype: Integer + expression: + sql: sales_amount + metrics: + - name: total_sales + description: Total sales amount + datatype: Integer + expression: + sql: SUM(sales_amount) + + - name: store_returns + source: stores.store_returns + primary_key: [return_id] + fields: + - name: return_id + datatype: String + expression: + sql: return_id + - name: item_id + datatype: String + expression: + sql: item_id + - name: return_date_id + datatype: String + expression: + sql: return_date_id + - name: return_amount + datatype: Integer + expression: + sql: return_amount + metrics: + - name: total_returns + description: Total return amount + datatype: Integer + expression: + sql: SUM(return_amount) + +relationships: + - name: store_sales_to_item + from: store_sales + to: item + from_columns: [item_id] + to_columns: [item_id] + - name: store_sales_to_sale_date + from: store_sales + to: date_dim + from_columns: [sale_date_id] + to_columns: [date_id] + - name: store_sales_to_store + from: store_sales + to: store + from_columns: [store_id] + to_columns: [store_id] + - name: store_sales_to_customers + from: store_sales + to: customers + from_columns: [customer_id] + to_columns: [customer_id] + - name: store_returns_to_item + from: store_returns + to: item + from_columns: [item_id] + to_columns: [item_id] + - name: store_returns_to_return_date + from: store_returns + to: date_dim + from_columns: [return_date_id] + to_columns: [date_id] + - name: store_to_closing_date + from: store + to: date_dim + from_columns: [closing_date_id] + to_columns: [date_id] diff --git a/compliance/wide_table/stores/stores_model.ossie.yaml b/compliance/wide_table/stores/stores_model.ossie.yaml new file mode 100644 index 00000000..00937297 --- /dev/null +++ b/compliance/wide_table/stores/stores_model.ossie.yaml @@ -0,0 +1,181 @@ +# 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. + +# yaml-language-server: $schema=../../../core-spec/ossie-schema.json +# +# Model over stores.sql (Appendix B.3). store_sales reaches date_dim only +# through sale_date_id. See stores_ambiguous_model.ossie.yaml for two paths. + +version: 0.3.0.dev0 +name: stores +description: Store sales and returns with item, date, store, and customer dimensions +datasets: + - name: date_dim + source: stores.date_dim + primary_key: [date_id] + fields: + - name: date_id + datatype: String + expression: + sql: date_id + - name: year + datatype: Integer + expression: + sql: year + + - name: item + source: stores.item + primary_key: [item_id] + fields: + - name: item_id + datatype: String + expression: + sql: item_id + - name: brand + datatype: String + expression: + sql: brand + + - name: store + source: stores.store + primary_key: [store_id] + fields: + - name: store_id + datatype: String + expression: + sql: store_id + - name: state + datatype: String + expression: + sql: state + - name: closing_date_id + datatype: String + expression: + sql: closing_date_id + + - name: customers + source: stores.customers + primary_key: [customer_id] + fields: + - name: customer_id + datatype: String + expression: + sql: customer_id + - name: region + datatype: String + expression: + sql: region + metrics: + - name: customer_count + description: Number of customers + datatype: Integer + expression: + sql: COUNT(*) + + - name: store_sales + source: stores.store_sales + primary_key: [sale_id] + fields: + - name: sale_id + datatype: String + expression: + sql: sale_id + - name: item_id + datatype: String + expression: + sql: item_id + - name: sale_date_id + datatype: String + expression: + sql: sale_date_id + - name: store_id + datatype: String + expression: + sql: store_id + - name: customer_id + datatype: String + expression: + sql: customer_id + - name: sales_amount + datatype: Integer + expression: + sql: sales_amount + metrics: + - name: total_sales + description: Total sales amount + datatype: Integer + expression: + sql: SUM(sales_amount) + + - name: store_returns + source: stores.store_returns + primary_key: [return_id] + fields: + - name: return_id + datatype: String + expression: + sql: return_id + - name: item_id + datatype: String + expression: + sql: item_id + - name: return_date_id + datatype: String + expression: + sql: return_date_id + - name: return_amount + datatype: Integer + expression: + sql: return_amount + metrics: + - name: total_returns + description: Total return amount + datatype: Integer + expression: + sql: SUM(return_amount) + +relationships: + - name: store_sales_to_item + from: store_sales + to: item + from_columns: [item_id] + to_columns: [item_id] + - name: store_sales_to_sale_date + from: store_sales + to: date_dim + from_columns: [sale_date_id] + to_columns: [date_id] + - name: store_sales_to_store + from: store_sales + to: store + from_columns: [store_id] + to_columns: [store_id] + - name: store_sales_to_customers + from: store_sales + to: customers + from_columns: [customer_id] + to_columns: [customer_id] + - name: store_returns_to_item + from: store_returns + to: item + from_columns: [item_id] + to_columns: [item_id] + - name: store_returns_to_return_date + from: store_returns + to: date_dim + from_columns: [return_date_id] + to_columns: [date_id]