Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](nereids)don't normalize column name for base index #26476

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -940,22 +939,28 @@ private static class CheckContext {

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);

// map<is_key, map<column_name, column>>
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
}