Skip to content

Commit fc2b9c3

Browse files
mergify[bot]Seaven
andauthored
[BugFix] Fix push down decimal window function error (backport #46199) (#46313)
Co-authored-by: Seaven <[email protected]>
1 parent 0fb71d8 commit fc2b9c3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/pdagg/PushDownDistinctAggregateRewriter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ public RewriteInfo visitLogicalWindow(OptExpression optExpression, RewriteInfo r
442442
Type[] argTypes = newArgs.stream().map(ScalarOperator::getType).toArray(Type[]::new);
443443
Function newFunc = Expr.getBuiltinFunction(funcName, argTypes,
444444
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
445+
if (FunctionSet.SUM.equals(funcName) && argTypes[0].isDecimalOfAnyVersion()) {
446+
newFunc = DecimalV3FunctionAnalyzer.rectifyAggregationFunction((AggregateFunction) newFunc,
447+
argTypes[0], rewriteCallOp.getType());
448+
}
445449
CallOperator newWindowCall = new CallOperator(funcName, newFunc.getReturnType(), newArgs, newFunc);
446450
newWindowCalls.put(entry.getKey(), newWindowCall);
447451
}

fe/fe-core/src/test/java/com/starrocks/sql/plan/AggregatePushDownTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,18 @@ public void testPruneColsAfterPushdownAgg_2() throws Exception {
218218
" | \n" +
219219
" 2:EXCHANGE");
220220
}
221+
222+
@Test
223+
public void testPruneDistinctWindow() throws Exception {
224+
String sql = "select distinct t1c, t1d, t1g, amount " +
225+
" from (" +
226+
" select t1b, t1c, t1d, t1g, id_date, \n" +
227+
" sum(id_decimal)over(partition by t1c) as amount\n" +
228+
"from test_all_type_not_null) tt";
229+
String plan = getVerboseExplain(sql);
230+
assertContains(plan, " 5:ANALYTIC\n" +
231+
" | functions: [, sum[([12: sum, DECIMAL128(38,2), true]);" +
232+
" args: DECIMAL128; result: DECIMAL128(38,2); args nullable: true; result nullable: true], ]");
233+
assertContains(plan, "2:AGGREGATE (update finalize)");
234+
}
221235
}

0 commit comments

Comments
 (0)