From 51537af57a2a28871a0dcc2e6fa3b42f2915c3c0 Mon Sep 17 00:00:00 2001 From: before-Sunrise <71162020+before-Sunrise@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:36:34 +0800 Subject: [PATCH] [BugFix] fix agg skew hint losing having (#53427) Signed-off-by: before-Sunrise --- .../GroupByCountDistinctDataSkewEliminateRule.java | 1 + .../java/com/starrocks/analysis/SelectStmtTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/GroupByCountDistinctDataSkewEliminateRule.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/GroupByCountDistinctDataSkewEliminateRule.java index 3bc3e580747de..0a66a4722f4d9 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/GroupByCountDistinctDataSkewEliminateRule.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/GroupByCountDistinctDataSkewEliminateRule.java @@ -170,6 +170,7 @@ public List transform(OptExpression input, OptimizerContext conte .setSplit() .setPartitionByColumns(Lists.newArrayList(groupBy)) .setProjection(aggOp.getProjection()) + .setPredicate(aggOp.getPredicate()) .build(); fourthAggOp.setDistinctColumnDataSkew(new DataSkewInfo(distinctColRef, 0.5, ++stage)); diff --git a/fe/fe-core/src/test/java/com/starrocks/analysis/SelectStmtTest.java b/fe/fe-core/src/test/java/com/starrocks/analysis/SelectStmtTest.java index ef5216b8bb2e3..c08516b75d605 100644 --- a/fe/fe-core/src/test/java/com/starrocks/analysis/SelectStmtTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/analysis/SelectStmtTest.java @@ -378,6 +378,19 @@ void testGroupByCountDistinctWithSkewHint() throws Exception { FeConstants.runningUnitTest = false; } + @Test + void testGroupByCountDistinctWithSkewHintLossPredicate() throws Exception { + FeConstants.runningUnitTest = true; + String sql = + "select t from(select cast(k1 as int), count(distinct [skew] cast(k2 as int)) as t from db1.tbl1 group by cast(k1 as int)) temp where t > 1"; + String s = starRocksAssert.query(sql).explainQuery(); + Assert.assertTrue(s, s.contains(" 8:AGGREGATE (merge finalize)\n" + + " | output: sum(7: count)\n" + + " | group by: 5: cast\n" + + " | having: 7: count > 1")); + FeConstants.runningUnitTest = false; + } + @Test void testGroupByMultiColumnCountDistinctWithSkewHint() throws Exception { FeConstants.runningUnitTest = true;