branch-2.1: [fix](Nereids) nested window function with order by raise exception #48492 (#48677)

Cherry-picked from #48492

Co-authored-by: morrySnow <zhangwenxin@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-03-05 17:30:09 +08:00
committed by GitHub
parent 155e908b0e
commit fc842fcbf6
2 changed files with 11 additions and 1 deletions

View File

@ -62,7 +62,7 @@ public class ExtractAndNormalizeWindowExpression extends OneRewriteRuleFactory i
if (output instanceof WindowExpression) {
WindowExpression windowExpression = (WindowExpression) output;
Expression expression = ((WindowExpression) output).getFunction();
if (expression.containsType(OrderExpression.class)) {
if (expression.children().stream().anyMatch(OrderExpression.class::isInstance)) {
throw new AnalysisException("order by is not supported in " + expression);
}
if (expression instanceof NullableAggregateFunction) {

View File

@ -77,6 +77,16 @@ suite("normalize_window_nullable_agg") {
exception "order by is not supported"
}
test {
sql "select group_concat(cast(sum(xwhat) over(partition by xwho order by xwhen) as varchar) order by xwhat) over(partition by xwhen) from windowfunnel_test_normalize_window;"
exception "order by is not supported"
}
// test only refuse order by in function's direct children
sql """
select sum(sum(xwhat) over(partition by xwho order by xwhen)) over(partition by xwho) from windowfunnel_test_normalize_window
"""
sql "set enable_fold_constant_by_be = 1;"
sql "drop table if exists fold_window1"
sql """create table fold_window1 (