feat(sql): Support RANK/DENSE_RANK for unified SQL - #5720
Conversation
PR Reviewer Guide 🔍(Review updated until commit 544e467)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 544e467 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 77ae6e0
Suggestions up to commit 747d1b6
Suggestions up to commit 352ffbd
|
352ffbd to
747d1b6
Compare
|
Persistent review updated to latest commit 747d1b6 |
747d1b6 to
77ae6e0
Compare
|
Persistent review updated to latest commit 77ae6e0 |
Both were accepted by the SQL grammar and declared as BuiltinFunctionName constants, but missing from WINDOW_FUNC_MAPPING, so visitWindowFunction rejected them with "Unexpected window function". Register both, extend the ROW_NUMBER bypass of aggregate signature validation since they likewise take no arguments, and lower them to SqlStdOperatorTable.RANK and DENSE_RANK. WINDOW_FUNC_MAPPING is shared, so PPL eventstats/streamstats now resolve these functions as well. Related to opensearch-project#5168 Signed-off-by: Chen Dai <daichen@amazon.com>
77ae6e0 to
544e467
Compare
|
Persistent review updated to latest commit 544e467 |
RANK/DENSE_RANK in unified SQLRANK/DENSE_RANK for unified SQL
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>
RyanL1997
left a comment
There was a problem hiding this comment.
LGTM. Just would like to double check do we need to add doc test/doc for this?
|
In addtion, I found out that
|
Description
RANK()andDENSE_RANK()were already accepted by the SQL grammar and declared as built-in function names, but were never registered as window functions, so planning failed withUnexpected window function: RANK. This PR registers both and maps them to Calcite's standardRANKandDENSE_RANKoperators. No grammar, lexer or AST changes were needed.Related Issues
Part of #5248
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.