This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 2562cf33a76 [fix](mtmv) Choose a valid partition column when there are
both valid and invalid expressions (#38367) (#38684)
2562cf33a76 is described below
commit 2562cf33a769e5622a605f7d298f03639c47b4e0
Author: Lijia Liu <[email protected]>
AuthorDate: Thu Aug 1 19:00:28 2024 +0800
[fix](mtmv) Choose a valid partition column when there are both valid and
invalid expressions (#38367) (#38684)
## Proposed changes
pick #38367
<!--Describe your changes.-->
---
.../exploration/mv/MaterializedViewUtils.java | 14 ++++---
.../exploration/mv/MaterializedViewUtilsTest.java | 49 ++++++++++++++++++++++
2 files changed, 57 insertions(+), 6 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java
index f1ce770de2d..66d4d185ad8 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java
@@ -522,7 +522,8 @@ public class MaterializedViewUtils {
private static boolean checkPartition(Collection<? extends Expression>
expressionsToCheck, Plan plan,
IncrementCheckerContext context) {
NamedExpression partitionColumn = context.getMvPartitionColumn();
- for (Expression projectSlot : expressionsToCheck) {
+
+ OUTER_CHECK: for (Expression projectSlot : expressionsToCheck) {
if (projectSlot.isColumnFromTable() &&
projectSlot.equals(partitionColumn.toSlot())) {
continue;
}
@@ -554,7 +555,7 @@ public class MaterializedViewUtils {
String.format("partition expression use more than
one slot reference, invalid "
+ "expressionToCheckColumns is %s,
partitionColumnDateColumns is %s",
expressionToCheckColumns,
partitionColumns));
- return false;
+ continue;
}
List<Expression> expressions =
expressionToCheck.collectToList(Expression.class::isInstance);
for (Expression expression : expressions) {
@@ -563,7 +564,7 @@ public class MaterializedViewUtils {
context.addFailReason(
String.format("column to check use invalid
implicit expression, invalid "
+ "expression is %s", expression));
- return false;
+ continue OUTER_CHECK;
}
}
List<Expression> partitionExpressions =
partitionExpression.collectToList(
@@ -574,7 +575,7 @@ public class MaterializedViewUtils {
context.addFailReason(
String.format("partition column use invalid
implicit expression, invalid "
+ "expression is %s", expression));
- return false;
+ continue OUTER_CHECK;
}
}
List<DateTrunc> expressionToCheckDataTruncList =
@@ -585,7 +586,7 @@ public class MaterializedViewUtils {
// mv time unit level is little then query
context.addFailReason("partition column time unit level
should be "
+ "greater than sql select column");
- return false;
+ continue;
}
if (!partitionColumn.isColumnFromTable()) {
context.setMvPartitionColumn(partitionColumns.iterator().next());
@@ -593,8 +594,9 @@ public class MaterializedViewUtils {
if (!context.getPartitionExpression().isPresent()) {
context.setPartitionExpression(partitionExpression);
}
+ return true;
}
- return true;
+ return context.getMvPartitionColumn().isColumnFromTable();
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java
index 89fe34876ae..9ac6d7d3a75 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java
@@ -234,6 +234,19 @@ public class MaterializedViewUtilsTest extends
TestWithFeService {
+ " \"replication_num\" = \"1\"\n"
+ ");\n"
);
+ createTable("CREATE TABLE `test3` (\n"
+ + " `id` VARCHAR(36) NOT NULL COMMENT 'id',\n"
+ + " `created_time` DATETIME(3) NOT NULL DEFAULT
CURRENT_TIMESTAMP COMMENT ''\n"
+ + ") ENGINE=OLAP\n"
+ + "DUPLICATE KEY(`id`)\n"
+ + "COMMENT ''\n"
+ + "PARTITION BY RANGE(`created_time`)\n"
+ + "(PARTITION P_2024071713 VALUES [('2024-07-17 13:00:00'),
('2024-07-17 14:00:00')),\n"
+ + "PARTITION P_2024071714 VALUES [('2024-07-17 14:00:00'),
('2024-07-17 15:00:00')))\n"
+ + "DISTRIBUTED BY HASH(`id`) BUCKETS AUTO\n"
+ + "PROPERTIES (\n"
+ + "\"replication_allocation\" = \"tag.location.default: 1\"\n"
+ + ");\n");
// Should not make scan to empty relation when the table used by
materialized view has no data
connectContext.getSessionVariable().setDisableNereidsRules("OLAP_SCAN_PARTITION_PRUNE,PRUNE_EMPTY_PARTITION");
}
@@ -809,6 +822,42 @@ public class MaterializedViewUtilsTest extends
TestWithFeService {
});
}
+ @Test
+ public void getRelatedTableInfoWhenMultiPartitionExprs() {
+ PlanChecker.from(connectContext)
+ .checkExplain("select id, date_trunc(created_time, 'minute')
as created_time_minute,"
+ + " min(created_time) as start_time,"
+ + " if(count(id) > 0, 1, 0) as status\n"
+ + " from test3 \n"
+ + " group by id,
date_trunc(created_time, 'minute')",
+ nereidsPlanner -> {
+ Plan rewrittenPlan =
nereidsPlanner.getRewrittenPlan();
+ RelatedTableInfo relatedTableInfo =
+
MaterializedViewUtils.getRelatedTableInfo("created_time_minute",
+ "day", rewrittenPlan,
nereidsPlanner.getCascadesContext());
+ checkRelatedTableInfo(relatedTableInfo,
+ "test3",
+ "created_time",
+ true);
+ });
+ PlanChecker.from(connectContext)
+ .checkExplain("select id, date_trunc(created_time, 'hour') as
created_time_hour,"
+ + " min(created_time) as start_time\n"
+ + " from test3 \n"
+ + " group by id,
date_trunc(created_time, 'minute'),"
+ + " date_trunc(created_time, 'hour');",
+ nereidsPlanner -> {
+ Plan rewrittenPlan =
nereidsPlanner.getRewrittenPlan();
+ RelatedTableInfo relatedTableInfo =
+
MaterializedViewUtils.getRelatedTableInfo("created_time_hour",
+ "day", rewrittenPlan,
nereidsPlanner.getCascadesContext());
+ checkRelatedTableInfo(relatedTableInfo,
+ "test3",
+ "created_time",
+ true);
+ });
+ }
+
private void checkRelatedTableInfo(RelatedTableInfo relatedTableInfo,
String expectTableName,
String expectColumnName,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]