[fix](planner) Fix agg on inlineview which with constant slot (#18201)

Since slot that reference to constant has been marked as constant expr either, just add condition check to make sure such slot wouldn't be eliminated as constant from group exprs
This commit is contained in:
AKIRA
2023-03-31 00:54:37 +09:00
committed by GitHub
parent 28793b6441
commit b5ea299697
4 changed files with 45 additions and 2 deletions

View File

@ -1387,7 +1387,7 @@ public class SelectStmt extends QueryStmt {
for (Expr groupExpr : groupingExprs) {
//remove groupExpr if it is const, and it is not in select list
boolean removeConstGroupingKey = false;
if (groupExpr.isConstant()) {
if (groupExpr.isConstant() && !(groupExpr.contains(e -> e instanceof SlotRef))) {
if (theFirstConstantGroupingExpr == null) {
theFirstConstantGroupingExpr = groupExpr;
}

View File

@ -0,0 +1,3 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --

View File

@ -0,0 +1,40 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("agg_on_view") {
sql """
create table test (
id int,
user_id int,
name varchar(20)
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""
qt_sql """
select user_id,null_or_empty(tag) = 1,count(*)
from (
select *,
"abc" as tag
from test limit 10)t
group by user_id,tag
"""
}

View File

@ -36,7 +36,7 @@ suite("constant_group_key") {
explain {
sql("select a from (select '1' as b, 'abc' as a) T group by b, a")
contains "group by: 'abc'"
contains "group by: '1', 'abc'"
}
sql "drop table if exists cgk_tbl"