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 2022/10/26 15:20:07 UTC

[doris] branch branch-1.1-lts updated: [fix](planner) cannot recogonize column's table when analyze rewrite expr (#13680)

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

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


The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
     new 1afa510aae [fix](planner) cannot recogonize column's table when analyze rewrite expr (#13680)
1afa510aae is described below

commit 1afa510aaef201a9acf56baeaf87a26597186dce
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Wed Oct 26 23:19:56 2022 +0800

    [fix](planner) cannot recogonize column's table when analyze rewrite expr (#13680)
    
    We save mv column with alias as table name, and search it with original table name.
    cherry-pick from master #13597
---
 .../java/org/apache/doris/analysis/SlotRef.java    |  5 ++
 .../org/apache/doris/analysis/TupleDescriptor.java | 15 +++++-
 .../correctness/test_mv_alias_table_name.groovy    | 63 ++++++++++++++++++++++
 3 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
index eafdd5fcbb..80c63347ba 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
@@ -31,6 +31,7 @@ import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -186,6 +187,10 @@ public class SlotRef extends Expr {
         if (type.equals(Type.BOOLEAN)) {
             selectivity = DEFAULT_SELECTIVITY;
         }
+        if (tblName == null && StringUtils.isNotEmpty(desc.getParent().getLastAlias())
+                && !desc.getParent().getLastAlias().equals(desc.getParent().getTable().getName())) {
+            tblName = new TableName(null, desc.getParent().getLastAlias());
+        }
     }
 
     @Override
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleDescriptor.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleDescriptor.java
index 9a7b7b7bd0..e7acb5db64 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleDescriptor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleDescriptor.java
@@ -161,8 +161,19 @@ public class TupleDescriptor {
         aliases_ = aliases;
         hasExplicitAlias_ = hasExplicitAlias;
     }
-    public boolean hasExplicitAlias() { return hasExplicitAlias_; }
-    public String getAlias() { return (aliases_ != null) ? aliases_[0] : null; }
+
+    public boolean hasExplicitAlias() {
+        return hasExplicitAlias_;
+    }
+
+    public String getAlias() {
+        return (aliases_ != null) ? aliases_[0] : null;
+    }
+
+    public String getLastAlias() {
+        return (aliases_ != null) ? aliases_[aliases_.length - 1] : null;
+    }
+
     public TableName getAliasAsName() {
         return (aliases_ != null) ? new TableName(null, aliases_[0]) : null;
     }
diff --git a/regression-test/suites/correctness/test_mv_alias_table_name.groovy b/regression-test/suites/correctness/test_mv_alias_table_name.groovy
new file mode 100644
index 0000000000..c588d002dc
--- /dev/null
+++ b/regression-test/suites/correctness/test_mv_alias_table_name.groovy
@@ -0,0 +1,63 @@
+// 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.
+
+
+/*
+exception throw before bug fix:  Unknown column 'mv_bitmap_union_mh' in 'default_cluster:test.original_table'
+*/
+suite("test_mv_alias_table_name") {
+    sql """
+        DROP TABLE IF EXISTS original_table;
+    """
+    sql """
+        CREATE TABLE original_table
+        (
+            day date,
+            aid bigint,
+            lid bigint,
+            yid bigint,
+            mh bigint,
+            my bigint
+        )
+        DUPLICATE KEY(`day`, `aid`, `lid`)
+        DISTRIBUTED BY HASH(aid)
+        PROPERTIES ("replication_num" = "1" );
+    """
+
+    sql """
+        create materialized view mv_table as
+        select day,aid,lid,
+            bitmap_union(to_bitmap(mh)) as wu,     
+            bitmap_union(to_bitmap(my)) as mu 
+        from original_table 
+        group by day, aid, lid;
+    """
+
+    sql """
+        insert into original_table values('2022-10-16', 1665710553, 1665710553, 1665710553, 1665700553, 1665700553);
+    """
+
+    sleep(2000)
+
+    sql """
+        select t0.aid, t0.lid, count(distinct mh), count(distinct my) 
+        from original_table t0 
+        where t0.day = '2022-10-16' and t0.lid > 0 group by t0.aid, t0.lid;
+    """
+
+ }
+


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