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

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new d749d99fe29 [fix](nereids)don't normalize column name for base index 
(#26476)
d749d99fe29 is described below

commit d749d99fe294182cc1d1ee826e61fc25bf3a4d50
Author: starocean999 <[email protected]>
AuthorDate: Wed Nov 8 20:45:58 2023 +0800

    [fix](nereids)don't normalize column name for base index (#26476)
---
 .../mv/SelectMaterializedIndexWithAggregate.java        | 17 +++++++++++------
 .../nereids_p0/with/test_with_and_two_phase_agg.groovy  | 10 +++++-----
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
index abc842cb9a8..1b6b26077fe 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
@@ -30,7 +30,6 @@ import org.apache.doris.nereids.parser.NereidsParser;
 import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.rules.rewrite.RewriteRuleFactory;
-import 
org.apache.doris.nereids.rules.rewrite.mv.AbstractSelectMaterializedIndexRule.SlotContext;
 import org.apache.doris.nereids.trees.expressions.Alias;
 import org.apache.doris.nereids.trees.expressions.Cast;
 import org.apache.doris.nereids.trees.expressions.ExprId;
@@ -940,6 +939,7 @@ public class SelectMaterializedIndexWithAggregate extends 
AbstractSelectMaterial
 
         public CheckContext(LogicalOlapScan scan, long indexId) {
             this.scan = scan;
+            boolean isBaseIndex = indexId == scan.getTable().getBaseIndexId();
 
             Supplier<Map<String, Column>> supplier = () -> 
Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
 
@@ -947,15 +947,20 @@ public class SelectMaterializedIndexWithAggregate extends 
AbstractSelectMaterial
             Map<Boolean, Map<String, Column>> baseNameToColumnGroupingByIsKey 
= scan.getTable()
                     .getSchemaByIndexId(indexId).stream()
                     .collect(Collectors.groupingBy(Column::isKey,
-                            Collectors.toMap(c -> 
normalizeName(parseMvColumnToSql(c.getName())), Function.identity(),
-                                    (v1, v2) -> v1, supplier)));
+                            Collectors.toMap(
+                                    c -> isBaseIndex ? c.getName()
+                                            : 
normalizeName(parseMvColumnToSql(c.getName())),
+                                    Function.identity(), (v1, v2) -> v1, 
supplier)));
             Map<Boolean, Map<String, Column>> mvNameToColumnGroupingByIsKey = 
scan.getTable()
                     .getSchemaByIndexId(indexId).stream()
                     .collect(Collectors.groupingBy(Column::isKey,
                             Collectors.toMap(
-                                    c -> 
normalizeName(parseMvColumnToMvName(c.getNameWithoutMvPrefix(),
-                                            c.isAggregated() ? 
Optional.of(c.getAggregationType().name())
-                                                    : Optional.empty())),
+                                    c -> isBaseIndex ? c.getName()
+                                            : 
normalizeName(parseMvColumnToMvName(
+                                                    c.getNameWithoutMvPrefix(),
+                                                    c.isAggregated()
+                                                            ? 
Optional.of(c.getAggregationType().name())
+                                                            : 
Optional.empty())),
                                     Function.identity(), (v1, v2) -> v1, 
supplier)));
 
             this.keyNameToColumn = 
mvNameToColumnGroupingByIsKey.getOrDefault(true,
diff --git 
a/regression-test/suites/nereids_p0/with/test_with_and_two_phase_agg.groovy 
b/regression-test/suites/nereids_p0/with/test_with_and_two_phase_agg.groovy
index 6b80546bc70..c7b5865219a 100644
--- a/regression-test/suites/nereids_p0/with/test_with_and_two_phase_agg.groovy
+++ b/regression-test/suites/nereids_p0/with/test_with_and_two_phase_agg.groovy
@@ -22,21 +22,21 @@ suite("test_with_and_two_phase_agg") {
     sql """ DROP TABLE IF EXISTS ${tableName} """
     sql """
         CREATE TABLE IF NOT EXISTS ${tableName}(
-            `key1` int not null,
+            `key` int not null,
             `key2` varchar(50) not null,
             `account` varchar(50) not null
         ) ENGINE = OLAP
-        UNIQUE KEY (`key1`, `key2`)
-        DISTRIBUTED BY HASH(`key1`)
+        UNIQUE KEY (`key`, `key2`)
+        DISTRIBUTED BY HASH(`key`)
         PROPERTIES("replication_num" = "1");
     """
     sql """ INSERT INTO ${tableName} VALUES (1, '1332050726', '1332050726'); 
"""
     qt_select """
-                WITH t2 AS( SELECT  sum(`key1`) num, COUNT(DISTINCT `account`) 
unt
+                WITH t2 AS( SELECT  sum(`key`) num, COUNT(DISTINCT `account`) 
unt
                 FROM ${tableName}) SELECT num FROM t2;
               """
     qt_select2 """
-                 WITH t2 AS( SELECT `key2`, sum(`key1`) num, COUNT(DISTINCT 
`account`) unt
+                 WITH t2 AS( SELECT `key2`, sum(`key`) num, COUNT(DISTINCT 
`account`) unt
                  FROM ${tableName} GROUP BY `key2`) SELECT num FROM t2;
               """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to