This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new 7e23657503d [Bug](mv)forbid create mv with condition about value
column on mow table #57913 (#57937)
7e23657503d is described below
commit 7e23657503d1b179bade63395186e9e7a353c0a0
Author: Pxl <[email protected]>
AuthorDate: Tue Nov 25 10:58:32 2025 +0800
[Bug](mv)forbid create mv with condition about value column on mow table
#57913 (#57937)
pick from #57913
---
.../doris/analysis/CreateMaterializedViewStmt.java | 4 ++--
.../main/java/org/apache/doris/analysis/Expr.java | 5 +++--
.../java/org/apache/doris/analysis/SlotRef.java | 9 ++++++++-
.../suites/mv_p0/where/k123/k123.groovy | 23 ++++++++++++++++++++++
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index bc1364a7d68..f5ba40bbf0e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -225,7 +225,7 @@ public class CreateMaterializedViewStmt extends DdlStmt
implements NotFallbackIn
mvKeysType = KeysType.AGG_KEYS;
}
if (selectStmt.getWhereClause() != null) {
- if (!isReplay && selectStmt.getWhereClause().hasAggregateSlot()) {
+ if (!isReplay &&
selectStmt.getWhereClause().hasAggregateSlot(getMVKeysType())) {
throw new AnalysisException(
"The where clause contained aggregate column is not
supported, expr:"
+ selectStmt.getWhereClause().toSql());
@@ -585,7 +585,7 @@ public class CreateMaterializedViewStmt extends DdlStmt
implements NotFallbackIn
mvAggregateType =
AggregateType.valueOf(functionName.toUpperCase());
}
- if (!isReplay && defineExpr.hasAggregateSlot()) {
+ if (!isReplay && defineExpr.hasAggregateSlot(getMVKeysType())) {
SlotRef slot = null;
if (defineExpr instanceof SlotRef) {
slot = (SlotRef) defineExpr;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
index 653fb92003a..3091a769568 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
@@ -28,6 +28,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.Function;
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionSet;
+import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.MapType;
import org.apache.doris.catalog.MaterializedIndexMeta;
import org.apache.doris.catalog.PrimitiveType;
@@ -2271,9 +2272,9 @@ public abstract class Expr extends TreeNode<Expr>
implements ParseNode, Cloneabl
return false;
}
- public boolean hasAggregateSlot() {
+ public boolean hasAggregateSlot(KeysType keysType) {
for (Expr expr : children) {
- if (expr.hasAggregateSlot()) {
+ if (expr.hasAggregateSlot(keysType)) {
return true;
}
}
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 3e8117e365b..485934af18e 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
@@ -22,6 +22,7 @@ package org.apache.doris.analysis;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.JdbcTable;
+import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.MaterializedIndexMeta;
import org.apache.doris.catalog.OdbcTable;
import org.apache.doris.catalog.TableIf;
@@ -499,7 +500,13 @@ public class SlotRef extends Expr {
}
@Override
- public boolean hasAggregateSlot() {
+ public boolean hasAggregateSlot(KeysType keysType) {
+ if (KeysType.UNIQUE_KEYS.equals(keysType)) {
+ Column column = getColumn();
+ if (column != null && !column.isKey()) {
+ return true;
+ }
+ }
return desc.getColumn().isAggregated();
}
diff --git a/regression-test/suites/mv_p0/where/k123/k123.groovy
b/regression-test/suites/mv_p0/where/k123/k123.groovy
index 366fc76580f..3527a889f83 100644
--- a/regression-test/suites/mv_p0/where/k123/k123.groovy
+++ b/regression-test/suites/mv_p0/where/k123/k123.groovy
@@ -87,4 +87,27 @@ suite ("k123p") {
mv_rewrite_success("""select k1,k2+k3 from d_table where k1 = 2 and k4 =
"b";""", "k123p4w")
+ sql """ DROP TABLE IF EXISTS u_table; """
+ sql """
+ create table u_table(
+ k1 int null,
+ k2 int not null,
+ k3 bigint null,
+ k4 varchar(100) null
+ )
+ unique key (k1,k2)
+ distributed BY hash(k1) buckets 3
+ properties("replication_num" = "1");
+ """
+
+ sql "insert into u_table select 1,1,1,'a';"
+ sql "insert into u_table select 2,2,2,'bb';"
+ sql "insert into u_table select 3,-3,null,'c';"
+
+ test {
+ sql """create materialized view k123p4w as select k1 as aa1,k2 as
aa2,k3 as aa3 from u_table where k4 = "b";"""
+ exception "The where clause contained aggregate column is not
supported"
+ }
+
+ createMV ("""create materialized view k123p1w as select k1 as a1,k2 as
a2,k3 as a3 from u_table where k1 = 1;""")
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]