Repository navigation
Conversation
…ipts lower and executeLower take a query of the Wide Table Query Interface in the JSON binding of Section 3.7 and lower it to the Layer 2 query of Section 5: a branch for each home dataset, with a LEFT JOIN for each step of each path, combined on the keys of Section 5.5. executeLower expands the lowering with the view expander and executes it. A query that raises an error of Section 8 gives an error that starts with its code, checked in the order of that table. Each component of a model-scoped metric that is not AGG(dataset.metric) becomes a measure of its home dataset with a name of its own, such as c1, so that the lowering evaluates it with AGG(), as Section 5.2 says. A comment at the start of the lowering defines each such measure. connect loads two new fixtures, retail and stores, with the data of compliance/wide_table; a unit test checks that they match. 16 of the 21 wide table cases that return rows are now scripts, compliance/wide_table/<case>.ost. The view expander does not support yet the lowering of the other five: a join without measures (a12) and a field whose expression is not its name (a16, a19 to a21). The expander's _expression becomes expression_text, which the lowering also uses.
A filter with an unterminated string, such as region = 'EAST, made sqlglot raise TokenError, which is not a ParseError, so the lowering failed with the tokenizer's message instead of E_INVALID_QUERY. The lowering now catches every sqlglot error when it parses a filter or a metric's expression. The lowering also rejects AGG with a FILTER clause, which the core specification does not allow (Metric Scoping, rule 6), instead of dropping the clause. And _parseexpression_text, a slip of the rename of _expression, becomes _parse_expression.
christianeu-db
left a comment
There was a problem hiding this comment.
@ekut this looks great and very close to merge - thanks for putting it together so quickly!
I left a few inline comments, but the main things I'd like to see before merging are:
Remove the old .json/.text fixtures so the .ost cases are the single source of truth.
Generate test files for all .ost cases, allowing unsupported cases to be skipped with a link to a tracking issue. The issues can be as simple as "Unskip test case XX."
That way, we have the full test corpus in place, with clear follow-ups for the remaining gaps.
| return Ref("field", dataset, f.name) | ||
| for m in dataset.metrics or []: | ||
| if normalize_name(m.name) == name: | ||
| return Ref("metric", dataset, m.name, m) |
There was a problem hiding this comment.
nit: kind == "metric" means a dataset-scoped metric only, so the checks in _metric that reject every other kind read as rejecting non-metrics, though they also reject model-scoped ones. Could the kinds be dataset_metric and model_metric, after the spec's two scopes?
| - The error cases as scripts. `ost` compares an error by its message, and the | ||
| cases check only the code. |
There was a problem hiding this comment.
nit: this drops the caveat that ost compares cell text exactly, but "Comparing results" still says 350.00 matches 350, and a script with 350.00 in a05 fails. Could that section say the scripts compare text?
| return None | ||
| text = self.query.filter_text | ||
| for node in f.walk(): | ||
| if isinstance(node, exp.AggFunc) and not node.find_ancestor(exp.Window): |
There was a problem hiding this comment.
Not a blocker: this skips every aggregate under a window, not only the window's own function, so an aggregate in its ORDER BY gives row 7 instead of E_AGGREGATE_IN_WHERE:
"filter": "ROW_NUMBER() OVER (ORDER BY SUM(orders.amount)) = 1"
> error: E_WINDOW_IN_WHERE: filter has a window function: ...
Could it skip only the call that the window applies to, as unwindowed_aggregates in validate.py does?
| 2. The expected result: the rows of `expected.txt`. | ||
|
|
||
| Cases `a12`, `a16`, `a19`, `a20`, and `a21` have no script yet, because the | ||
| view expander does not support their lowering: `a12` joins two datasets |
There was a problem hiding this comment.
Could we open an issue for each of these (a join without a measure, and a field whose expression differs from its name) and link them in the PR? That would give the five pending cases something concrete to track against.
I've opened a few issues against the expander and have seen really fast community turnarounds so far. Perhaps we could follow a similar pattern here:
- Add a skip annotation to the .ost format and generate the test files for all five cases.
- Skipped cases remain in the test suite but aren't executed.
- Each skip includes an issue ID, so contributors can find and pick up the work.
- The exit criterion for closing an issue is a PR that removes the skip and gets the test passing.
That gives us a complete set of test cases, makes the remaining work easy to discover, and avoids maintaining a separate list of exceptions in the README.
| cases check only the code. | ||
| - Scripts for `a12`, `a16`, `a19`, `a20`, and `a21`, when the view expander | ||
| supports their lowering. | ||
| - One file per case. The scripts repeat `query.json` and `expected.txt`. |
There was a problem hiding this comment.
Could we remove the old json / expected as part of thsi PR (and this line in the readme). Then, we have a single source of truth
Follow-up to #716: steps (3) and (4) of the next steps in the review, and the first of the two PRs planned in #707.
ostgets a reference lowering of Layer 3 queries to Layer 2 queries, and 16 of the wide table cases become.ostscripts. For example,compliance/wide_table/a05_groups_from_orders.ostruns itsquery.jsonand expects the lowering, then the rows of itsexpected.txt:The lowering is in
ost/src/ossie_ost/lowering.pyand followscore-spec/wide_table_semantics.md:E_NO_PATH: metric ....LEFT JOINfor each step of each path (Sections 4 and 5.4).b_<home dataset>andkeys. A component whose empty-input value is not NULL, such asCOUNT(*), takes it where its branch has no row, through apresentcolumn. Without dimensions, the branches are cross joined.New in
ost, documented inost/docs/ost.md:lower(model, query)returns the Layer 2 query, andexecuteLower(model, query)also expands and executes it. The query is the JSON of Section 3.7, written as the last argument.connect("retail")andconnect("stores")load the data ofcompliance/wide_table. A unit test checks that the copies match.make compliance-wide-tableand theostCI workflow run the scripts._expressionis nowexpression_text, because the lowering reads metric expressions too.Points for reviewers:
a08,SUM(orders.amount)becomes the measurec1oforders, andexecuteLowerexpands the query over the model with these measures. A comment at the start of the lowering defines each one, such as-- orders.c1 is SUM(amount). A component in a branch with joins is then evaluated byAGG().a08'squery.ossie.sqluses a plain aggregate, which gives the same value only in a branch without joins.a12,a16,a19,a20anda21have no script yet. Their lowering returns the expected rows when each measure, field and dataset is replaced by hand (see Checks), but the expander does not expand it.a12joins two relations of a model without evaluating a measure. The others usedate_dim.year, whose expression isd_year. Neither gap is among expander: A SELECT DISTINCT that passes a measure through gives a wrong answer instead of an error #786 to expander: A view that reads a view is expanded one level only #791.cases/stays as it is, so the scripts repeatquery.jsonandexpected.txt. feat(compliance): add Layer 3 B.6 fan-out cases and polish B.6 #742 and feat(core-spec): name a dataset-scoped metric's column by its reference (breaking) #778 change files there, and the README lists one file per case as future work.orders.total_revenue. The lowering and the scripts would change with it. If feat(compliance): add Layer 3 B.6 fan-out cases and polish B.6 #742 lands first, thestoresfixture copies its new rows, and the unit test above catches a mismatch.fromtotoonly, as an absentcardinalitymeans, so no case here changes. If feat(core-spec): make relationship cardinality explicit #794 lands first, the lowering must also follow a OneToMany or OneToOne relationship fromtotofrom. I can add that here or in a follow-up.ost/tests/scripts/lowering.ostalready tests each code of Section 8, and six pairs of rows for the order of the table.Checks:
executeLower: the 25 error cases give their code, and the 16 scripted cases give the rows ofexpected.txt.a12,a16,a19,a20anda21, a script took the output oflower, replaced each measure, field and dataset with its expression or source table, and ran it on DuckDB. All five return the rows ofexpected.txt. Every join in them goes from the many side to a primary key, so no row repeats.ost,uv run pytest(175 tests) andost tests/scriptspass.ost -d compliance compliance/query compliance/wide_tablepasses all 48 scripts, anddev/check-licensepasses.cc @christianeu-db @jbonofre