[fix](fe)predicate is wrongly pushed through CUBE function (#15831)

This commit is contained in:
starocean999
2023-02-06 11:29:15 +08:00
committed by GitHub
parent f2fd47f238
commit dccd04a3ba
3 changed files with 25 additions and 5 deletions

View File

@ -2667,8 +2667,10 @@ public class SingleNodePlanner {
//eg: select distinct c from ( select distinct c from table) t where c > 1;
continue;
}
if (stmt.getGroupByClause().isGroupByExtension()
&& stmt.getGroupByClause().getGroupingExprs().contains(sourceExpr)) {
if (sourceExpr.getFn() instanceof AggregateFunction) {
isAllSlotReferToGroupBys = false;
} else if (stmt.getGroupByClause().isGroupByExtension()) {
// if grouping type is CUBE or ROLLUP will definitely produce null
if (stmt.getGroupByClause().getGroupingType() == GroupByClause.GroupingType.CUBE
|| stmt.getGroupByClause().getGroupingType() == GroupByClause.GroupingType.ROLLUP) {
@ -2684,9 +2686,6 @@ public class SingleNodePlanner {
}
}
}
if (sourceExpr.getFn() instanceof AggregateFunction) {
isAllSlotReferToGroupBys = false;
}
}
if (isAllSlotReferToGroupBys) {

View File

@ -49,3 +49,6 @@
-- !select7 --
-- !select8 --
test 2

View File

@ -60,4 +60,22 @@ suite("test_grouping_sets") {
}
qt_select7 """ select k1,k2,sum(k3) from test_query_db.test where 1 = 2 group by grouping sets((k1), (k1,k2)) """
qt_select8 """ WITH dt AS
(select 'test' as name,1 as score
UNION
all
SELECT 'test' AS name,1 AS score
UNION
all SELECT 'test2' AS name,12 AS score
UNION
all SELECT 'test2' AS name,12 AS score ) ,result_data AS
(SELECT name,
sum(score) AS score
FROM dt
GROUP BY CUBE(name))
SELECT *
FROM result_data
WHERE name = 'test';
"""
}