Improve error message for unsupported window functions in eventstats/streamstats - #5600
Conversation
…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. Fixes opensearch-project#5168 Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
PR Reviewer Guide 🔍(Review updated until commit 99c53f5)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 99c53f5
Previous suggestionsSuggestions up to commit c16fc0c
|
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
|
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.
|
@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 |
|
@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! |
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)