From dd5fe6f3f2fb95b140dc888051e7f78dad107fde Mon Sep 17 00:00:00 2001 From: starocean999 <12095047@qq.com> Date: Mon, 6 Nov 2023 20:10:13 +0800 Subject: [PATCH] [fix](nereids)don't normalize column name for base index --- .../SelectMaterializedIndexWithAggregate.java | 17 +++++++++++------ .../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 abc842cb9a86ed..1b6b26077fe857 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.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 @@ private static class CheckContext { public CheckContext(LogicalOlapScan scan, long indexId) { this.scan = scan; + boolean isBaseIndex = indexId == scan.getTable().getBaseIndexId(); Supplier> supplier = () -> Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); @@ -947,15 +947,20 @@ public CheckContext(LogicalOlapScan scan, long indexId) { Map> 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> 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 6b80546bc70185..c7b5865219a0aa 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; """ }