Uh oh!
There was an error while loading. Please reload this page.
Improve error message for unsupported window functions in eventstats/streamstats - #5600
Conversation
PR Reviewer Guide 🔍(Review updated until commit dd3ca1c)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to dd3ca1c Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 58fda66
Suggestions up to commit cf4cb1b
Suggestions up to commit 99c53f5
Suggestions up to commit c16fc0c
|
Persistent review updated to latest commit 99c53f5 |
dai-chen
left a comment
There was a problem hiding this comment.
Hi, I'm trying to add support for rank and dense_rank function in Calcite for unified SQL for analytics engine. If we confirm both are not supported by PPL evenstats and streamstats, shall we remove them from PPL grammar directly? I assume that's the only place window function can be used. Otherwise it will be tricky to check language type in Calcite planner.
gingeekrishna
commented
Aug 25, 2026
@dai-chen Good question — I dug into this a bit. Your assumption holds for PPL specifically: in the PPL grammar, But it's not the only place in the engine overall. SQL has its own Practical implication: if you add So yes, I think removing One side note on this PR itself: the new error message I added ("Window function 'x' is not supported in eventstats/streamstats") is thrown from that same shared visitor, so it would also currently fire — misleadingly — for a plain SQL |
dai-chen
commented
Aug 26, 2026
@gingeekrishna Thanks for digging in! I've put up PR #5720 for the SQL side. As you confirmed, removing them from grammar should make PPL reject at parse time and leaves my change SQL-only. With both PRs merged, I think we get the language separation at parse time rather than in the planner, which is where it belongs as expected. Thanks! |
gingeekrishna
commented
Aug 28, 2026
@dai-chen Nice, thanks for #5720. Pushed Updated the tests this PR added for that case ( One caveat: I don't have a Java toolchain in my current environment, so I couldn't run |
Persistent review updated to latest commit da13116 |
…streamstats Window functions outside WINDOW_FUNC_MAPPING (e.g. rank, dense_rank, nth_value) throw a generic "Unexpected window function: X" from CalciteRexNodeVisitor#visitWindowFunction. These functions require ORDER BY semantics that eventstats/streamstats don't have (they only support partition-by), so they are intentionally unsupported, not a bug -- but the error message gave users no indication of what to use instead. Replace the message with one that names the function and lists the functions eventstats/streamstats do support, so users get actionable guidance instead of a bare "unexpected" error. Fixesopensearch-project#5168 Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
WINDOW_FUNC_MAPPING (used by eventstats/streamstats) never supported rank/dense_rank, but PPL's scalarWindowFunctionName grammar rule still accepted the tokens, so `eventstats rank()` reached CalciteRexNodeVisitor#visitWindowFunction and failed there with the "not supported" message this PR improves. Meanwhile SQL's grammar already accepts RANK()/DENSE_RANK() OVER (...), and opensearch-project#5720 is adding real support for them on the SQL side via the same shared visitor. Remove RANK/DENSE_RANK from scalarWindowFunctionName so PPL rejects them at parse time instead of falling through to the shared SQL/PPL visitor - this keeps the language separation at the parser rather than relying on a WINDOW_FUNC_MAPPING check in shared planner code, and avoids PPL silently gaining rank/dense_rank as a side effect of opensearch-project#5720 registering them for SQL. Updates the eventstats/streamstats tests added earlier in this PR to expect a SyntaxCheckException (parse-time) instead of the semantic "not supported" error, and switches the unrelated visitWindowFunction-rejection unit test from rank() to percent_rank(), which remains unsupported and still exercises that code path. Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
da13116 to
cf4cb1bComparePersistent review updated to latest commit cf4cb1b |
dai-chen
commented
Aug 31, 2026
@gingeekrishna My PR was already merged. You can rebase and verify yours by CI if you're unable locally. Btw, I recall changes in |
| + " Supported functions: avg, count, dc, distinct_count, earliest," | ||
| + " latest, max, min, row_number, stddev_pop, stddev_samp, sum," | ||
| + " var_pop, var_samp.")); |
There was a problem hiding this comment.
maybe revert this change because this list is dynamic and defined in grammar.
dai-chen
left a comment
There was a problem hiding this comment.
Minor comment. Thanks for the changes!
dai-chen
commented
Sep 1, 2026
I retried Linter CI but it still failed. Probably worth taking another look. |
… time" This reverts commit cf4cb1b. The "PPL grammar compatibility" CI check failed after that commit: [ppl-lint-grammar] FAILED unsupported-window-function-in-eventstats/ eventstats-rank: expected 1, got 0 That check runs OpenSearch-Dashboards' own PPL linter (fetched via `yarn osd bootstrap`) against this repo's grammar bundle, using test cases from scripts/ppl-lint/grammar-cases.json. Its "unsupported-window-function-in-eventstats" rule expects `eventstats rank()` to parse successfully and then be flagged by a semantic-layer diagnostic (giving IDE users a specific, friendly error). Removing RANK/DENSE_RANK from the PPL grammar made the query fail to parse at all, so that rule never gets a chance to run and the diagnostic it's supposed to produce disappears - the ppl-lint test expects the rule to fire (count 1) but the query now dies earlier with a raw syntax error instead (count 0). The rule implementation lives in OpenSearch-Dashboards, not this repo, so fixing this properly would need a coordinated cross-repo change. Reverting restores parsing (and the linter's diagnostic) while keeping the actual point of this PR - the improved "Window function 'x' is not supported in eventstats/streamstats" message from CalciteRexNodeVisitor - fully intact, since that's a semantic-layer check unaffected by this revert. Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
gingeekrishna
commented
Sep 2, 2026
Found it - pushed The failing check was the linter, specifically: That's OpenSearch-Dashboards' own PPL linter (fetched via My earlier commit here ( Reverted that commit. This PR's actual point - the improved |
Persistent review updated to latest commit 58fda66 |
…layer opensearch-project#5720 added rank/dense_rank to the WINDOW_FUNC_MAPPING shared by both SQL's RANK()/DENSE_RANK() OVER (...) and PPL's eventstats/streamstats, which silently enabled them for eventstats/streamstats too: testRankingWindowFunctionsUnsupportedInEventstats/InStreamstats (added earlier in this PR) started failing with "expected ResponseException to be thrown, but nothing was thrown" once opensearch-project#5720 merged, since eventstats rank() now builds a real window call instead of hitting the "not supported" check. That's a real gap, not just a test artifact: PPL's eventstats/ streamstats grammar has no ORDER BY syntax at all, so ranking has no defined ordering to rank by there - unlike SQL's OVER(), which at least has (optional) ORDER BY in its own clause. A prior commit on this branch tried fixing this by removing RANK/ DENSE_RANK from the PPL grammar entirely, rejecting them at parse time. That broke a different, cross-repo contract: OpenSearch- Dashboards' PPL linter (validated by the "PPL grammar compatibility" CI check) expects `eventstats rank()` to parse successfully and be flagged by a semantic-layer diagnostic instead, so it could no longer produce that diagnostic once the query stopped parsing. That commit was reverted. Fix this at the semantic layer instead, where it belongs: PPL only ever reaches CalciteRexNodeVisitor#visitWindowFunction through eventstats/streamstats (no other PPL syntax builds a WindowFunction node), so context.queryType == PPL is an exact, unambiguous signal for "this is an eventstats/streamstats call". Filter rank/dense_rank out of the WINDOW_FUNC_MAPPING lookup specifically when queryType is PPL, so they fall through to the existing "not supported in eventstats/ streamstats" error - exactly the pre-opensearch-project#5720 behavior - while leaving SQL's RANK()/DENSE_RANK() OVER (...) handling (and everything else) completely untouched. Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
Persistent review updated to latest commit dd3ca1c |
Description
Fixes#5168
eventstats/streamstatsreject window functions outsideWINDOW_FUNC_MAPPING(e.g.rank(),dense_rank(),nth_value()) with a bare"Unexpected window function: X"error.As confirmed in the issue discussion by @songkant-aws, this is expected behavior, not a bug —
rank/dense_rank/nth_valuerequireORDER BYsemantics, buteventstats/streamstatsonly supportpartition by. The issue was relabelederror-experience: the fix is to make the error message clearer, not to add support for these functions.Changes
CalciteRexNodeVisitor#visitWindowFunction: replaced the generic"Unexpected window function: X"message with one that names the rejected function and lists the functionseventstats/streamstatsdo support (sourced fromWINDOW_FUNC_MAPPING), so users get actionable guidance instead of a bare error.UnifiedQueryPlannerTest) and integration tests (CalcitePPLEventstatsIT,CalciteStreamstatsCommandIT) to assert against the new message.rank/dense_rankspecifically, since the issue's repro queries used those functions.Note: this PR builds on top of #5587 (already merged), which fixed the same throw site to return a 4xx instead of a 500. This PR only changes the message text, not the exception type or HTTP status.
Test plan
UnifiedQueryPlannerTest#unsupportedWindowFunctionIsRethrownAsSemanticCheckExceptionpasseseventstatsandstreamstats(require a live cluster to run in CI)