Repository navigation
feat(ost): lower Layer 3 queries, and run the wide table cases as scripts - #803
Conversation
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?
There was a problem hiding this comment.
Done in b5c831e: the kinds are now dataset_metric and model_metric.
| - 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?
There was a problem hiding this comment.
Done. "Comparing results" now says that types are not compared, so 350.00 from an implementation matches 350, and that ost compares the text of each cell, so a script that expects 350.00 in a05 fails.
| 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?
There was a problem hiding this comment.
Done in b5c831e. The check skips only the function of the window, with _is_windowed as in validate.py, and your filter now gives E_AGGREGATE_IN_WHERE. lowering.ost also covers an aggregate in PARTITION BY and in the argument of the windowed function, and FILTER before OVER.
| 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.
There was a problem hiding this comment.
Done. ost has skip(reason) now, documented in ost/docs/ost.md: it does not run the next command and keeps its expected output as written. The five cases are scripts, each after a skip with its issue: #813 for a12, and #814 for a16, a19, a20 and a21. Their expected output is the lowering and the rows of the case, so a fix only has to remove the skip. A unit test checks that each skip in compliance/ names an issue by its URL.
There was a problem hiding this comment.
| 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
There was a problem hiding this comment.
Done: cases/ is gone, and each script is the only copy of its case. That includes query.ossie.sql and cases/README.md, since each script carries the lowering and the description of the case.
…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.
skip(reason) makes ost not run the next command, and keep its expected output as written, so a script can hold a test whose feature is missing, with the output that it should produce. The reason, typically the URL of the issue that tracks the gap, must not be empty; the fix removes the skip.
…es under a window A reference to a dataset-scoped metric has kind dataset_metric instead of metric, after the two scopes of the core specification, so the checks that reject other kinds no longer read as rejecting non-metrics. The check for an aggregate in a filter (Section 8, row 7) skipped every aggregate under a window. It now skips only the window's own function, as unwindowed_aggregates in validate.py does, so an aggregate in the window's ORDER BY or PARTITION BY, or in an argument of the windowed function, raises E_AGGREGATE_IN_WHERE instead of E_WINDOW_IN_WHERE.
Each of the 46 cases is now a script, and the scripts are the only copy of the cases: the case folders, with query.json, expected.txt, query.ossie.sql, and cases/README.md, are removed. Each script carries the query, the lowering, the expected result, and the description of the case. The 25 error cases expect the error of the ost lowering; README.md says that a case requires only its code. Cases a12, a16, a19, a20, and a21 are skipped, each with the issue of the view expander that it waits on; their expected output is the lowering and the rows of the case.
…me an issue skip now fails, and skips nothing, if no command follows it, and its reason must have a character other than a space; ost.md says so, and that the next command is the next one after blank lines and comments, even another skip. A unit test checks that each skip in a compliance script names an issue of apache/ossie by its URL. The comment on the aggregate-under-a-window tests names rows 6 and 7 of Section 8, not 7 and 8.
a12 waits on apache#813, and a16, a19, a20, and a21 on apache#814. The check of the skips reads the scripts, not the regenerated copies under target/.
32bc163 to
9f76a8f
Compare
cdc3ac1 to
9f76a8f
Compare
christianeu-db
left a comment
There was a problem hiding this comment.
@ekut LGTM, thanks! I replied on the README thread about the skip list; that's fine as a follow-up
A step of the Layer 3 lowering now crosses a relationship from `from` to `to` if its cardinality is ManyToOne, the default, or OneToOne, and from `to` to `from` if it is OneToMany or OneToOne (Section 4). The join condition starts from the dataset where the step starts. retail_model declares customers_to_visits from customers, as OneToMany, so a03 crosses it from visits to customers and lowers as before. a22 groups visits by customer region, and e26 checks that customers does not reach visits. With the lowering of apache#803, a22 raises E_NO_PATH and e26 lowers to one row per visit. Co-authored-by: Isaac <no-reply@databricks.com>
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 each of the 46 wide table cases becomes an.ostscript, which replaces the case's folder. For example,compliance/wide_table/a05_groups_from_orders.ostruns the query of the case and expects the lowering, then the rows of the result: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.skip(reason)does not run the next command, and keeps its expected output as written, for a case thatostcannot run yet. The reason is the URL of the issue that tracks the gap.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().a12,a16,a19,a20anda21are skipped. Their lowering returns the expected rows when the gap is worked around (see Checks), but the expander does not expand it:a12joins two relations of a model without evaluating a measure (expander: A join of model relations that evaluates no measure is refused #813), and the others usedate_dim.year, whose expression isd_year(expander: A dataset with a field whose expression is not its name cannot be read #814).cases/is removed:query.json,expected.txt,query.ossie.sqlandcases/README.md. Each script has the query, the lowering, the expected result and the description of its case. 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 incases/, so whichever lands after this PR moves its cases into scripts.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. Per the thread on #794, this PR lands first, and feat(core-spec): make relationship cardinality explicit #794 then extends the lowering to follow a OneToMany or OneToOne relationship fromtotofrom.ostlowering. A case requires only the code at its start; the README says so.Checks:
ost -d compliance compliance/query compliance/wide_tablepasses all 78 scripts, with the fiveskips. The 25 error cases give the codes of the formerexpected.txt.a12, the lowering run as plain SQL on theretaildata returns the rows of its script. Fora16,a19,a20anda21, a script renamed the columnd_yeartoyearand set the field's expression toyear, andexecuteLowerthen returned the rows of each script. Every join in them goes from the many side to a primary key, so no row repeats.ost,uv run pytest(179 tests) andost tests/scriptspass, and so domake compliance-validateanddev/check-license.cc @christianeu-db @jbonofre