You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/03 15:10:18 UTC

[doris] 05/07: [fix](planner) Fix agg on inlineview which with constant slot (#18201)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit ab45f53fb4a74970d5b1403c4ffa0449d30a6dee
Author: AKIRA <33...@users.noreply.github.com>
AuthorDate: Fri Mar 31 00:54:37 2023 +0900

    [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
---
 .../java/org/apache/doris/analysis/SelectStmt.java |  2 +-
 .../data/query_p0/aggregate/agg_on_view.out        |  3 ++
 .../suites/query_p0/aggregate/agg_on_view.groovy   | 40 ++++++++++++++++++++++
 .../suites/trino_p0/constant_group_key.groovy      |  2 +-
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 0baffbc15f..3c8e288fb0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -1203,7 +1203,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;
                         }
diff --git a/regression-test/data/query_p0/aggregate/agg_on_view.out b/regression-test/data/query_p0/aggregate/agg_on_view.out
new file mode 100644
index 0000000000..9c9c4c6c8a
--- /dev/null
+++ b/regression-test/data/query_p0/aggregate/agg_on_view.out
@@ -0,0 +1,3 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !sql --
+
diff --git a/regression-test/suites/query_p0/aggregate/agg_on_view.groovy b/regression-test/suites/query_p0/aggregate/agg_on_view.groovy
new file mode 100644
index 0000000000..9f700283e1
--- /dev/null
+++ b/regression-test/suites/query_p0/aggregate/agg_on_view.groovy
@@ -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
+    """
+}
\ No newline at end of file
diff --git a/regression-test/suites/trino_p0/constant_group_key.groovy b/regression-test/suites/trino_p0/constant_group_key.groovy
index cd159722a3..d666b5244c 100644
--- a/regression-test/suites/trino_p0/constant_group_key.groovy
+++ b/regression-test/suites/trino_p0/constant_group_key.groovy
@@ -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"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org