diff --git a/Makefile b/Makefile index 912d5d93..19528670 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/compliance/README.md b/compliance/README.md index e6003b54..85f25f58 100644 --- a/compliance/README.md +++ b/compliance/README.md @@ -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). diff --git a/compliance/wide_table/README.md b/compliance/wide_table/README.md new file mode 100644 index 00000000..dbf0208e --- /dev/null +++ b/compliance/wide_table/README.md @@ -0,0 +1,104 @@ + + +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//query.json` | Query under test, in the JSON binding of Section 3.7 | +| `cases//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. diff --git a/compliance/wide_table/cases/a01_shared_dimension/expected.json b/compliance/wide_table/cases/a01_shared_dimension/expected.json new file mode 100644 index 00000000..8e8a7bae --- /dev/null +++ b/compliance/wide_table/cases/a01_shared_dimension/expected.json @@ -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.", + "spec": ["1.3", "5.4", "5.5"], + "columns": ["region", "total_revenue", "total_returns"], + "rows": [ + ["EAST", 350, 25], + ["WEST", 300, null], + ["NORTH", null, 10] + ] +} diff --git a/compliance/wide_table/cases/a01_shared_dimension/query.json b/compliance/wide_table/cases/a01_shared_dimension/query.json new file mode 100644 index 00000000..1af10e1a --- /dev/null +++ b/compliance/wide_table/cases/a01_shared_dimension/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue", "returns.total_returns"] +} diff --git a/compliance/wide_table/cases/a02_count_empty_input/expected.json b/compliance/wide_table/cases/a02_count_empty_input/expected.json new file mode 100644 index 00000000..7e340045 --- /dev/null +++ b/compliance/wide_table/cases/a02_count_empty_input/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a02_count_empty_input/query.json b/compliance/wide_table/cases/a02_count_empty_input/query.json new file mode 100644 index 00000000..575fa163 --- /dev/null +++ b/compliance/wide_table/cases/a02_count_empty_input/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue", "returns.return_count"] +} diff --git a/compliance/wide_table/cases/a03_three_branches/expected.json b/compliance/wide_table/cases/a03_three_branches/expected.json new file mode 100644 index 00000000..8ba16a57 --- /dev/null +++ b/compliance/wide_table/cases/a03_three_branches/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a03_three_branches/query.json b/compliance/wide_table/cases/a03_three_branches/query.json new file mode 100644 index 00000000..b8b12d2d --- /dev/null +++ b/compliance/wide_table/cases/a03_three_branches/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue", "returns.total_returns", "visits.visit_count"] +} diff --git a/compliance/wide_table/cases/a04_filter_on_dimension/expected.json b/compliance/wide_table/cases/a04_filter_on_dimension/expected.json new file mode 100644 index 00000000..07ca7bcd --- /dev/null +++ b/compliance/wide_table/cases/a04_filter_on_dimension/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a04_filter_on_dimension/query.json b/compliance/wide_table/cases/a04_filter_on_dimension/query.json new file mode 100644 index 00000000..293b39e5 --- /dev/null +++ b/compliance/wide_table/cases/a04_filter_on_dimension/query.json @@ -0,0 +1,5 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue", "returns.total_returns"], + "filter": "customers.region <> 'EAST'" +} diff --git a/compliance/wide_table/cases/a05_groups_from_orders/expected.json b/compliance/wide_table/cases/a05_groups_from_orders/expected.json new file mode 100644 index 00000000..8f3fce39 --- /dev/null +++ b/compliance/wide_table/cases/a05_groups_from_orders/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a05_groups_from_orders/query.json b/compliance/wide_table/cases/a05_groups_from_orders/query.json new file mode 100644 index 00000000..50e5892b --- /dev/null +++ b/compliance/wide_table/cases/a05_groups_from_orders/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue"] +} diff --git a/compliance/wide_table/cases/a06_groups_from_returns/expected.json b/compliance/wide_table/cases/a06_groups_from_returns/expected.json new file mode 100644 index 00000000..51447d12 --- /dev/null +++ b/compliance/wide_table/cases/a06_groups_from_returns/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a06_groups_from_returns/query.json b/compliance/wide_table/cases/a06_groups_from_returns/query.json new file mode 100644 index 00000000..bd76907e --- /dev/null +++ b/compliance/wide_table/cases/a06_groups_from_returns/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["returns.total_returns"] +} diff --git a/compliance/wide_table/cases/a07_dimension_only/expected.json b/compliance/wide_table/cases/a07_dimension_only/expected.json new file mode 100644 index 00000000..d3b42139 --- /dev/null +++ b/compliance/wide_table/cases/a07_dimension_only/expected.json @@ -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"] + ] +} diff --git a/compliance/wide_table/cases/a07_dimension_only/query.json b/compliance/wide_table/cases/a07_dimension_only/query.json new file mode 100644 index 00000000..94105a80 --- /dev/null +++ b/compliance/wide_table/cases/a07_dimension_only/query.json @@ -0,0 +1,3 @@ +{ + "dimensions": ["customers.region"] +} diff --git a/compliance/wide_table/cases/a08_model_metric_components/expected.json b/compliance/wide_table/cases/a08_model_metric_components/expected.json new file mode 100644 index 00000000..f436a2c2 --- /dev/null +++ b/compliance/wide_table/cases/a08_model_metric_components/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a08_model_metric_components/query.json b/compliance/wide_table/cases/a08_model_metric_components/query.json new file mode 100644 index 00000000..e3ff7271 --- /dev/null +++ b/compliance/wide_table/cases/a08_model_metric_components/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["revenue_per_customer"] +} diff --git a/compliance/wide_table/cases/a09_aliases/expected.json b/compliance/wide_table/cases/a09_aliases/expected.json new file mode 100644 index 00000000..518a05ea --- /dev/null +++ b/compliance/wide_table/cases/a09_aliases/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a09_aliases/query.json b/compliance/wide_table/cases/a09_aliases/query.json new file mode 100644 index 00000000..ea388272 --- /dev/null +++ b/compliance/wide_table/cases/a09_aliases/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": [{"field": "customers.region", "alias": "area"}], + "metrics": [{"metric": "orders.total_revenue", "alias": "revenue"}] +} diff --git a/compliance/wide_table/cases/a10_filter_without_dimension/expected.json b/compliance/wide_table/cases/a10_filter_without_dimension/expected.json new file mode 100644 index 00000000..42a27614 --- /dev/null +++ b/compliance/wide_table/cases/a10_filter_without_dimension/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a10_filter_without_dimension/query.json b/compliance/wide_table/cases/a10_filter_without_dimension/query.json new file mode 100644 index 00000000..54c292c5 --- /dev/null +++ b/compliance/wide_table/cases/a10_filter_without_dimension/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue"], + "filter": "customers.region = 'EAST'" +} diff --git a/compliance/wide_table/cases/a11_filter_on_home_dataset/expected.json b/compliance/wide_table/cases/a11_filter_on_home_dataset/expected.json new file mode 100644 index 00000000..b2b71fa2 --- /dev/null +++ b/compliance/wide_table/cases/a11_filter_on_home_dataset/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a11_filter_on_home_dataset/query.json b/compliance/wide_table/cases/a11_filter_on_home_dataset/query.json new file mode 100644 index 00000000..d475d96e --- /dev/null +++ b/compliance/wide_table/cases/a11_filter_on_home_dataset/query.json @@ -0,0 +1,5 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue"], + "filter": "orders.amount > 100" +} diff --git a/compliance/wide_table/cases/a12_anchor_from_dimensions/expected.json b/compliance/wide_table/cases/a12_anchor_from_dimensions/expected.json new file mode 100644 index 00000000..01b8840b --- /dev/null +++ b/compliance/wide_table/cases/a12_anchor_from_dimensions/expected.json @@ -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"] + ] +} diff --git a/compliance/wide_table/cases/a12_anchor_from_dimensions/query.json b/compliance/wide_table/cases/a12_anchor_from_dimensions/query.json new file mode 100644 index 00000000..d6bf897b --- /dev/null +++ b/compliance/wide_table/cases/a12_anchor_from_dimensions/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["orders.order_id", "customers.region"], + "filter": "orders.amount > 100" +} diff --git a/compliance/wide_table/cases/a13_filter_false_with_dimension/expected.json b/compliance/wide_table/cases/a13_filter_false_with_dimension/expected.json new file mode 100644 index 00000000..ed9f14c0 --- /dev/null +++ b/compliance/wide_table/cases/a13_filter_false_with_dimension/expected.json @@ -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": [] +} diff --git a/compliance/wide_table/cases/a13_filter_false_with_dimension/query.json b/compliance/wide_table/cases/a13_filter_false_with_dimension/query.json new file mode 100644 index 00000000..6d8ccd3c --- /dev/null +++ b/compliance/wide_table/cases/a13_filter_false_with_dimension/query.json @@ -0,0 +1,5 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue"], + "filter": "FALSE" +} diff --git a/compliance/wide_table/cases/a14_filter_false_without_dimension/expected.json b/compliance/wide_table/cases/a14_filter_false_without_dimension/expected.json new file mode 100644 index 00000000..367f8617 --- /dev/null +++ b/compliance/wide_table/cases/a14_filter_false_without_dimension/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a14_filter_false_without_dimension/query.json b/compliance/wide_table/cases/a14_filter_false_without_dimension/query.json new file mode 100644 index 00000000..7fee6847 --- /dev/null +++ b/compliance/wide_table/cases/a14_filter_false_without_dimension/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue"], + "filter": "FALSE" +} diff --git a/compliance/wide_table/cases/a15_unconnected_filter_false/expected.json b/compliance/wide_table/cases/a15_unconnected_filter_false/expected.json new file mode 100644 index 00000000..ab3bae6b --- /dev/null +++ b/compliance/wide_table/cases/a15_unconnected_filter_false/expected.json @@ -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] + ] +} diff --git a/compliance/wide_table/cases/a15_unconnected_filter_false/query.json b/compliance/wide_table/cases/a15_unconnected_filter_false/query.json new file mode 100644 index 00000000..6d298d3e --- /dev/null +++ b/compliance/wide_table/cases/a15_unconnected_filter_false/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue", "tickets.ticket_count"], + "filter": "FALSE" +} diff --git a/compliance/wide_table/cases/e01_invalid_query_unknown_key/expected.json b/compliance/wide_table/cases/e01_invalid_query_unknown_key/expected.json new file mode 100644 index 00000000..2404ea85 --- /dev/null +++ b/compliance/wide_table/cases/e01_invalid_query_unknown_key/expected.json @@ -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" +} diff --git a/compliance/wide_table/cases/e01_invalid_query_unknown_key/query.json b/compliance/wide_table/cases/e01_invalid_query_unknown_key/query.json new file mode 100644 index 00000000..52b23749 --- /dev/null +++ b/compliance/wide_table/cases/e01_invalid_query_unknown_key/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue"], + "limit": 10 +} diff --git a/compliance/wide_table/cases/e02_invalid_query_null/expected.json b/compliance/wide_table/cases/e02_invalid_query_null/expected.json new file mode 100644 index 00000000..1dc51a31 --- /dev/null +++ b/compliance/wide_table/cases/e02_invalid_query_null/expected.json @@ -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" +} diff --git a/compliance/wide_table/cases/e02_invalid_query_null/query.json b/compliance/wide_table/cases/e02_invalid_query_null/query.json new file mode 100644 index 00000000..9aecd477 --- /dev/null +++ b/compliance/wide_table/cases/e02_invalid_query_null/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue"], + "filter": null +} diff --git a/compliance/wide_table/cases/e03_empty_aggregation_query/expected.json b/compliance/wide_table/cases/e03_empty_aggregation_query/expected.json new file mode 100644 index 00000000..c8f1e704 --- /dev/null +++ b/compliance/wide_table/cases/e03_empty_aggregation_query/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A query needs a dimension or a metric", + "question": "(A query with only a filter.)", + "behavior": "All parts are optional, but at least one dimension or metric is required.", + "spec": ["3.2", "8"], + "error": "E_EMPTY_AGGREGATION_QUERY" +} diff --git a/compliance/wide_table/cases/e03_empty_aggregation_query/query.json b/compliance/wide_table/cases/e03_empty_aggregation_query/query.json new file mode 100644 index 00000000..31a1eb30 --- /dev/null +++ b/compliance/wide_table/cases/e03_empty_aggregation_query/query.json @@ -0,0 +1,3 @@ +{ + "filter": "TRUE" +} diff --git a/compliance/wide_table/cases/e04_name_not_found/expected.json b/compliance/wide_table/cases/e04_name_not_found/expected.json new file mode 100644 index 00000000..56b55c6d --- /dev/null +++ b/compliance/wide_table/cases/e04_name_not_found/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A reference must resolve", + "question": "What is orders.no_such_metric?", + "behavior": "orders has no field or metric of that name.", + "spec": ["3.2", "8"], + "error": "E_NAME_NOT_FOUND" +} diff --git a/compliance/wide_table/cases/e04_name_not_found/query.json b/compliance/wide_table/cases/e04_name_not_found/query.json new file mode 100644 index 00000000..accaeaaf --- /dev/null +++ b/compliance/wide_table/cases/e04_name_not_found/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["orders.no_such_metric"] +} diff --git a/compliance/wide_table/cases/e05_metric_in_dimensions/expected.json b/compliance/wide_table/cases/e05_metric_in_dimensions/expected.json new file mode 100644 index 00000000..b659adf4 --- /dev/null +++ b/compliance/wide_table/cases/e05_metric_in_dimensions/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A dimension must name a field", + "question": "(A metric used as a dimension.)", + "behavior": "orders.total_revenue is a metric.", + "spec": ["3.2", "8"], + "error": "E_METRIC_IN_DIMENSIONS" +} diff --git a/compliance/wide_table/cases/e05_metric_in_dimensions/query.json b/compliance/wide_table/cases/e05_metric_in_dimensions/query.json new file mode 100644 index 00000000..e4d230eb --- /dev/null +++ b/compliance/wide_table/cases/e05_metric_in_dimensions/query.json @@ -0,0 +1,3 @@ +{ + "dimensions": ["orders.total_revenue"] +} diff --git a/compliance/wide_table/cases/e06_field_in_metrics/expected.json b/compliance/wide_table/cases/e06_field_in_metrics/expected.json new file mode 100644 index 00000000..d3861f4f --- /dev/null +++ b/compliance/wide_table/cases/e06_field_in_metrics/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A metric entry must name a metric", + "question": "(A field used as a metric.)", + "behavior": "orders.amount is a field.", + "spec": ["3.2", "8"], + "error": "E_FIELD_IN_METRICS" +} diff --git a/compliance/wide_table/cases/e06_field_in_metrics/query.json b/compliance/wide_table/cases/e06_field_in_metrics/query.json new file mode 100644 index 00000000..d72f3485 --- /dev/null +++ b/compliance/wide_table/cases/e06_field_in_metrics/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["orders.amount"] +} diff --git a/compliance/wide_table/cases/e07_aggregate_in_filter/expected.json b/compliance/wide_table/cases/e07_aggregate_in_filter/expected.json new file mode 100644 index 00000000..0ef5f162 --- /dev/null +++ b/compliance/wide_table/cases/e07_aggregate_in_filter/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A filter cannot contain an aggregate", + "question": "(A filter on an aggregate.)", + "behavior": "The filter applies to rows before aggregation.", + "spec": ["3.4", "8"], + "error": "E_AGGREGATE_IN_WHERE" +} diff --git a/compliance/wide_table/cases/e07_aggregate_in_filter/query.json b/compliance/wide_table/cases/e07_aggregate_in_filter/query.json new file mode 100644 index 00000000..7b083d7f --- /dev/null +++ b/compliance/wide_table/cases/e07_aggregate_in_filter/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue"], + "filter": "SUM(orders.amount) > 100" +} diff --git a/compliance/wide_table/cases/e08_window_in_filter/expected.json b/compliance/wide_table/cases/e08_window_in_filter/expected.json new file mode 100644 index 00000000..cfb566d4 --- /dev/null +++ b/compliance/wide_table/cases/e08_window_in_filter/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A filter cannot contain a window function", + "question": "(A filter on a row number.)", + "behavior": "The filter is a row predicate.", + "spec": ["3.4", "8"], + "error": "E_WINDOW_IN_WHERE" +} diff --git a/compliance/wide_table/cases/e08_window_in_filter/query.json b/compliance/wide_table/cases/e08_window_in_filter/query.json new file mode 100644 index 00000000..06998c2a --- /dev/null +++ b/compliance/wide_table/cases/e08_window_in_filter/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["orders.order_id"], + "filter": "ROW_NUMBER() OVER (ORDER BY orders.amount) = 1" +} diff --git a/compliance/wide_table/cases/e09_cross_dataset_filter/expected.json b/compliance/wide_table/cases/e09_cross_dataset_filter/expected.json new file mode 100644 index 00000000..158339c9 --- /dev/null +++ b/compliance/wide_table/cases/e09_cross_dataset_filter/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A filter reads one dataset", + "question": "What is the amount of orders over 100 from customers in EAST?", + "behavior": "The filter reads orders and customers. A Layer 2 query can express it.", + "spec": ["3.4", "7", "8"], + "error": "E_CROSS_DATASET_FILTER" +} diff --git a/compliance/wide_table/cases/e09_cross_dataset_filter/query.json b/compliance/wide_table/cases/e09_cross_dataset_filter/query.json new file mode 100644 index 00000000..8a6677f5 --- /dev/null +++ b/compliance/wide_table/cases/e09_cross_dataset_filter/query.json @@ -0,0 +1,4 @@ +{ + "metrics": ["orders.total_revenue"], + "filter": "orders.amount > 100 AND customers.region = 'EAST'" +} diff --git a/compliance/wide_table/cases/e10_name_collision/expected.json b/compliance/wide_table/cases/e10_name_collision/expected.json new file mode 100644 index 00000000..981abefc --- /dev/null +++ b/compliance/wide_table/cases/e10_name_collision/expected.json @@ -0,0 +1,7 @@ +{ + "title": "Output names must be unique", + "question": "(Two columns named region.)", + "behavior": "The alias of the second dimension equals the output name of the first.", + "spec": ["3.3", "8"], + "error": "E_NAME_COLLISION" +} diff --git a/compliance/wide_table/cases/e10_name_collision/query.json b/compliance/wide_table/cases/e10_name_collision/query.json new file mode 100644 index 00000000..599dc54c --- /dev/null +++ b/compliance/wide_table/cases/e10_name_collision/query.json @@ -0,0 +1,3 @@ +{ + "dimensions": ["customers.region", {"field": "customers.customer_id", "alias": "region"}] +} diff --git a/compliance/wide_table/cases/e11_unaggregated_field_in_metric/expected.json b/compliance/wide_table/cases/e11_unaggregated_field_in_metric/expected.json new file mode 100644 index 00000000..1848daa4 --- /dev/null +++ b/compliance/wide_table/cases/e11_unaggregated_field_in_metric/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A model-scoped metric with a field outside every aggregate", + "question": "What is amount_less_order?", + "behavior": "orders.amount is outside SUM.", + "spec": ["5.2", "8"], + "error": "E_UNAGGREGATED_FINER_GRAIN_REFERENCE" +} diff --git a/compliance/wide_table/cases/e11_unaggregated_field_in_metric/query.json b/compliance/wide_table/cases/e11_unaggregated_field_in_metric/query.json new file mode 100644 index 00000000..5286424a --- /dev/null +++ b/compliance/wide_table/cases/e11_unaggregated_field_in_metric/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["amount_less_order"] +} diff --git a/compliance/wide_table/cases/e12_windowed_metric/expected.json b/compliance/wide_table/cases/e12_windowed_metric/expected.json new file mode 100644 index 00000000..95e99e6c --- /dev/null +++ b/compliance/wide_table/cases/e12_windowed_metric/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A model-scoped metric with a window function is deferred", + "question": "What is running_revenue?", + "behavior": "The metric uses OVER.", + "spec": ["5.2", "8"], + "error": "E_DEFERRED_WINDOWED_METRIC" +} diff --git a/compliance/wide_table/cases/e12_windowed_metric/query.json b/compliance/wide_table/cases/e12_windowed_metric/query.json new file mode 100644 index 00000000..8f3231fb --- /dev/null +++ b/compliance/wide_table/cases/e12_windowed_metric/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["running_revenue"] +} diff --git a/compliance/wide_table/cases/e13_measure_grain_two_datasets/expected.json b/compliance/wide_table/cases/e13_measure_grain_two_datasets/expected.json new file mode 100644 index 00000000..0a7d7c74 --- /dev/null +++ b/compliance/wide_table/cases/e13_measure_grain_two_datasets/expected.json @@ -0,0 +1,7 @@ +{ + "title": "An aggregate whose arguments read two datasets is deferred", + "question": "What is order_less_return?", + "behavior": "SUM reads orders.amount and returns.amount.", + "spec": ["5.2", "8"], + "error": "E_AMBIGUOUS_MEASURE_GRAIN" +} diff --git a/compliance/wide_table/cases/e13_measure_grain_two_datasets/query.json b/compliance/wide_table/cases/e13_measure_grain_two_datasets/query.json new file mode 100644 index 00000000..ff64ef70 --- /dev/null +++ b/compliance/wide_table/cases/e13_measure_grain_two_datasets/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["order_less_return"] +} diff --git a/compliance/wide_table/cases/e14_measure_grain_no_dataset/expected.json b/compliance/wide_table/cases/e14_measure_grain_no_dataset/expected.json new file mode 100644 index 00000000..2b7f6820 --- /dev/null +++ b/compliance/wide_table/cases/e14_measure_grain_no_dataset/expected.json @@ -0,0 +1,7 @@ +{ + "title": "An aggregate whose arguments read no dataset", + "question": "What is row_count?", + "behavior": "COUNT(*) in a model-scoped metric has no home dataset. A dataset-scoped COUNT(*) expresses the count.", + "spec": ["5.2", "8"], + "error": "E_AMBIGUOUS_MEASURE_GRAIN" +} diff --git a/compliance/wide_table/cases/e14_measure_grain_no_dataset/query.json b/compliance/wide_table/cases/e14_measure_grain_no_dataset/query.json new file mode 100644 index 00000000..80ae0eb0 --- /dev/null +++ b/compliance/wide_table/cases/e14_measure_grain_no_dataset/query.json @@ -0,0 +1,3 @@ +{ + "metrics": ["row_count"] +} diff --git a/compliance/wide_table/cases/e15_no_path/expected.json b/compliance/wide_table/cases/e15_no_path/expected.json new file mode 100644 index 00000000..65192a20 --- /dev/null +++ b/compliance/wide_table/cases/e15_no_path/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A dimension no metric reaches", + "question": "How many customers are there per order?", + "behavior": "customers does not reach orders: relationships are many-to-one, from orders to customers. The error names orders.order_id and customers.customer_count.", + "spec": ["4", "5.3", "8"], + "error": "E_NO_PATH" +} diff --git a/compliance/wide_table/cases/e15_no_path/query.json b/compliance/wide_table/cases/e15_no_path/query.json new file mode 100644 index 00000000..557b9afc --- /dev/null +++ b/compliance/wide_table/cases/e15_no_path/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["orders.order_id"], + "metrics": ["customers.customer_count"] +} diff --git a/compliance/wide_table/cases/e16_partial_dimension_reachability/expected.json b/compliance/wide_table/cases/e16_partial_dimension_reachability/expected.json new file mode 100644 index 00000000..d31c1db1 --- /dev/null +++ b/compliance/wide_table/cases/e16_partial_dimension_reachability/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A dimension some metrics reach", + "question": "What are the order amount and the number of tickets by customer region?", + "behavior": "orders reaches customers; tickets does not. The error names customers.region and tickets.ticket_count.", + "spec": ["5.3", "8", "B.4"], + "error": "E_PARTIAL_DIMENSION_REACHABILITY" +} diff --git a/compliance/wide_table/cases/e16_partial_dimension_reachability/query.json b/compliance/wide_table/cases/e16_partial_dimension_reachability/query.json new file mode 100644 index 00000000..cf4bcb52 --- /dev/null +++ b/compliance/wide_table/cases/e16_partial_dimension_reachability/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue", "tickets.ticket_count"] +} diff --git a/compliance/wide_table/cases/e17_no_anchor/expected.json b/compliance/wide_table/cases/e17_no_anchor/expected.json new file mode 100644 index 00000000..a7ed725d --- /dev/null +++ b/compliance/wide_table/cases/e17_no_anchor/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A query without metrics needs an anchor", + "question": "Which pairs of orders and returns are there?", + "behavior": "Neither orders nor returns reaches the other.", + "spec": ["5.6", "8"], + "error": "E_NO_ANCHOR" +} diff --git a/compliance/wide_table/cases/e17_no_anchor/query.json b/compliance/wide_table/cases/e17_no_anchor/query.json new file mode 100644 index 00000000..3c50ebbf --- /dev/null +++ b/compliance/wide_table/cases/e17_no_anchor/query.json @@ -0,0 +1,3 @@ +{ + "dimensions": ["orders.order_id", "returns.return_id"] +} diff --git a/compliance/wide_table/cases/e18_filter_path_from_metric/expected.json b/compliance/wide_table/cases/e18_filter_path_from_metric/expected.json new file mode 100644 index 00000000..8741494d --- /dev/null +++ b/compliance/wide_table/cases/e18_filter_path_from_metric/expected.json @@ -0,0 +1,7 @@ +{ + "title": "Every metric must reach the dataset of the filter", + "question": "What are the order and return amounts by customer region, for orders over 100?", + "behavior": "returns does not reach orders. The error names the filter and returns.total_returns.", + "spec": ["5.3", "8", "B.5"], + "error": "E_UNSUPPORTED_FILTER_PATH" +} diff --git a/compliance/wide_table/cases/e18_filter_path_from_metric/query.json b/compliance/wide_table/cases/e18_filter_path_from_metric/query.json new file mode 100644 index 00000000..3aa8b892 --- /dev/null +++ b/compliance/wide_table/cases/e18_filter_path_from_metric/query.json @@ -0,0 +1,5 @@ +{ + "dimensions": ["customers.region"], + "metrics": ["orders.total_revenue", "returns.total_returns"], + "filter": "orders.amount > 100" +} diff --git a/compliance/wide_table/cases/e19_filter_path_from_anchor/expected.json b/compliance/wide_table/cases/e19_filter_path_from_anchor/expected.json new file mode 100644 index 00000000..2c212be2 --- /dev/null +++ b/compliance/wide_table/cases/e19_filter_path_from_anchor/expected.json @@ -0,0 +1,7 @@ +{ + "title": "The anchor must reach the dataset of the filter", + "question": "Which customer regions have orders over 100?", + "behavior": "The anchor is customers, which does not reach orders. The error names the filter and the anchor.", + "spec": ["5.6", "8", "B.5"], + "error": "E_UNSUPPORTED_FILTER_PATH" +} diff --git a/compliance/wide_table/cases/e19_filter_path_from_anchor/query.json b/compliance/wide_table/cases/e19_filter_path_from_anchor/query.json new file mode 100644 index 00000000..93dc7049 --- /dev/null +++ b/compliance/wide_table/cases/e19_filter_path_from_anchor/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.region"], + "filter": "orders.amount > 100" +} diff --git a/compliance/wide_table/cases/e20_order_invalid_before_name/expected.json b/compliance/wide_table/cases/e20_order_invalid_before_name/expected.json new file mode 100644 index 00000000..66cdb655 --- /dev/null +++ b/compliance/wide_table/cases/e20_order_invalid_before_name/expected.json @@ -0,0 +1,7 @@ +{ + "title": "The first matching row of Section 8 wins", + "question": "(An unknown part and an unknown reference.)", + "behavior": "Both E_INVALID_QUERY (row 1) and E_NAME_NOT_FOUND (row 3) apply. Row 1 comes first.", + "spec": ["8"], + "error": "E_INVALID_QUERY" +} diff --git a/compliance/wide_table/cases/e20_order_invalid_before_name/query.json b/compliance/wide_table/cases/e20_order_invalid_before_name/query.json new file mode 100644 index 00000000..1a2ebd88 --- /dev/null +++ b/compliance/wide_table/cases/e20_order_invalid_before_name/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.no_such_field"], + "limit": 10 +} diff --git a/compliance/wide_table/cases/e21_order_name_before_filter/expected.json b/compliance/wide_table/cases/e21_order_name_before_filter/expected.json new file mode 100644 index 00000000..4861a761 --- /dev/null +++ b/compliance/wide_table/cases/e21_order_name_before_filter/expected.json @@ -0,0 +1,7 @@ +{ + "title": "A reference error comes before a filter error", + "question": "(An unknown reference and a filter over two datasets.)", + "behavior": "Both E_NAME_NOT_FOUND (row 3) and E_CROSS_DATASET_FILTER (row 8) apply. Row 3 comes first.", + "spec": ["8"], + "error": "E_NAME_NOT_FOUND" +} diff --git a/compliance/wide_table/cases/e21_order_name_before_filter/query.json b/compliance/wide_table/cases/e21_order_name_before_filter/query.json new file mode 100644 index 00000000..0fe2c65b --- /dev/null +++ b/compliance/wide_table/cases/e21_order_name_before_filter/query.json @@ -0,0 +1,4 @@ +{ + "dimensions": ["customers.no_such_field"], + "filter": "orders.amount > 100 AND customers.region = 'EAST'" +} diff --git a/compliance/wide_table/retail/retail.sql b/compliance/wide_table/retail/retail.sql new file mode 100644 index 00000000..2256022e --- /dev/null +++ b/compliance/wide_table/retail/retail.sql @@ -0,0 +1,78 @@ +-- 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: customers, orders, returns, visits, and tickets +-- +-- Shared input data for the wide table compliance cases in ../cases/. Load +-- this file before a case runs. Do not change the values: the expected results +-- of all cases depend on them. +-- +-- The rows of customers, orders, returns, and visits are the tables of +-- core-spec/wide_table_semantics.md, Appendix B.1 and B.2. The specification +-- gives no rows for tickets (Appendix B.4), so the table is empty. +-- ============================================================================ + +DROP SCHEMA IF EXISTS retail CASCADE; +CREATE SCHEMA retail; + +CREATE TABLE retail.customers ( + customer_id VARCHAR NOT NULL PRIMARY KEY, + region VARCHAR NOT NULL +); + +INSERT INTO retail.customers VALUES + ('C1', 'EAST'), + ('C2', 'EAST'), + ('C3', 'WEST'), + ('C4', 'NORTH'); + +CREATE TABLE retail.orders ( + order_id VARCHAR NOT NULL PRIMARY KEY, + customer_id VARCHAR NOT NULL, + amount INTEGER NOT NULL +); + +INSERT INTO retail.orders VALUES + ('O1', 'C1', 100), + ('O2', 'C1', 200), + ('O3', 'C2', 50), + ('O4', 'C3', 300); + +CREATE TABLE retail.returns ( + return_id VARCHAR NOT NULL PRIMARY KEY, + customer_id VARCHAR NOT NULL, + amount INTEGER NOT NULL +); + +INSERT INTO retail.returns VALUES + ('R1', 'C1', 25), + ('R2', 'C4', 10); + +CREATE TABLE retail.visits ( + visit_id VARCHAR NOT NULL PRIMARY KEY, + customer_id VARCHAR NOT NULL +); + +INSERT INTO retail.visits VALUES + ('V1', 'C4'), + ('V2', 'C4'), + ('V3', 'C3'); + +CREATE TABLE retail.tickets ( + ticket_id VARCHAR NOT NULL PRIMARY KEY +); diff --git a/compliance/wide_table/retail/retail_model.ossie.yaml b/compliance/wide_table/retail/retail_model.ossie.yaml new file mode 100644 index 00000000..fc48337e --- /dev/null +++ b/compliance/wide_table/retail/retail_model.ossie.yaml @@ -0,0 +1,184 @@ +# 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 +# +# Ossie semantic model over retail.sql, for the wide table compliance cases in +# ../cases/. It is the model of core-spec/wide_table_semantics.md, Appendix B: +# orders, returns, and visits relate to customers, and tickets relates to no +# dataset (B.4). +# +# Every dataset-scoped metric is one component (Section 5.2). The model-scoped +# metric revenue_per_customer has two components, as in Section 5.2. It casts +# its numerator to DOUBLE: the SQL standard leaves the scale of a division of +# two exact numerics implementation-defined (../../query/README.md, "Result +# semantics"). +# +# The other model-scoped metrics are rejected when a query names them (Section +# 5.2). They exist for the error cases. + +version: 0.3.0.dev0 +name: retail +description: Customers with orders, returns, and visits, and unrelated tickets +datasets: + - name: customers + source: retail.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: orders + source: retail.orders + primary_key: [order_id] + fields: + - name: order_id + datatype: String + expression: + sql: order_id + - name: customer_id + datatype: String + expression: + sql: customer_id + - name: amount + datatype: Integer + expression: + sql: amount + metrics: + - name: total_revenue + description: Total order amount + datatype: Integer + expression: + sql: SUM(amount) + + - name: returns + source: retail.returns + primary_key: [return_id] + fields: + - name: return_id + datatype: String + expression: + sql: return_id + - name: customer_id + datatype: String + expression: + sql: customer_id + - name: amount + datatype: Integer + expression: + sql: amount + metrics: + - name: total_returns + description: Total return amount + datatype: Integer + expression: + sql: SUM(amount) + - name: return_count + description: Number of returns + datatype: Integer + expression: + sql: COUNT(*) + + - name: visits + source: retail.visits + primary_key: [visit_id] + fields: + - name: visit_id + datatype: String + expression: + sql: visit_id + - name: customer_id + datatype: String + expression: + sql: customer_id + metrics: + - name: visit_count + description: Number of visits + datatype: Integer + expression: + sql: COUNT(*) + + - name: tickets + source: retail.tickets + primary_key: [ticket_id] + fields: + - name: ticket_id + datatype: String + expression: + sql: ticket_id + metrics: + - name: ticket_count + description: Number of tickets + datatype: Integer + expression: + sql: COUNT(*) + +relationships: + - name: orders_to_customers + from: orders + to: customers + from_columns: [customer_id] + to_columns: [customer_id] + - name: returns_to_customers + from: returns + to: customers + from_columns: [customer_id] + to_columns: [customer_id] + - name: visits_to_customers + from: visits + to: customers + from_columns: [customer_id] + to_columns: [customer_id] + +metrics: + - name: revenue_per_customer + description: Order amount per customer, counting customers without orders + datatype: Float + expression: + sql: CAST(SUM(orders.amount) AS DOUBLE) / COUNT(DISTINCT customers.customer_id) + - name: amount_less_order + description: Rejected, a field outside every aggregate + datatype: Integer + expression: + sql: SUM(orders.amount) - orders.amount + - name: running_revenue + description: Rejected, a window function + datatype: Integer + expression: + sql: SUM(SUM(orders.amount)) OVER () + - name: order_less_return + description: Rejected, an aggregate whose arguments read two datasets + datatype: Integer + expression: + sql: SUM(orders.amount - returns.amount) + - name: row_count + description: Rejected, an aggregate whose arguments read no dataset + datatype: Integer + expression: + sql: COUNT(*)