This is an automated email from the ASF dual-hosted git repository.
panxiaolei 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 9c1e86f84f [Bug](materialized-view) add some limit for create mv on
aggregate table (#18141)
9c1e86f84f is described below
commit 9c1e86f84f98f33b0427869e5b3da802790e0eb9
Author: Pxl <[email protected]>
AuthorDate: Tue Mar 28 10:28:29 2023 +0800
[Bug](materialized-view) add some limit for create mv on aggregate table
(#18141)
add some limit for create mv on aggregate table.
```sql
CREATE TABLE t1 (
p1 INT,
p2 INT,
p3 INT,
v1 INT SUM,
v2 INT MAX,
v3 INT MIN ) AGGREGATE KEY (p1, p2, p3) DISTRIBUTED BY HASH (p1) BUCKETS 1
PROPERTIES ('replication_num' = '1');
CREATE MATERIALIZED VIEW mv_1 AS SELECT p1, SUM(v3) FROM t1 GROUP BY p1;
// invalid aggregate type
CREATE MATERIALIZED VIEW mv_2 AS SELECT p1, MIN(v3+v3) FROM t1 GROUP BY p1;
// invalid expression calculate on aggregate column
CREATE MATERIALIZED VIEW mv_3 AS SELECT p1, SUM(v1) FROM t1 GROUP BY p1; //
cast v1 as bigint, ok
CREATE MATERIALIZED VIEW mv_4 AS SELECT p1, SUM(abs(v1)) FROM t1 GROUP BY
p1; // invalid expression calculate on aggregate column
```
---
.../doris/analysis/CreateMaterializedViewStmt.java | 18 ++++++++
.../main/java/org/apache/doris/analysis/Expr.java | 9 ++++
.../java/org/apache/doris/analysis/SlotRef.java | 5 +++
.../mv_p0/test_mv_useless/agg_invalid.groovy | 49 ++++++++++++++++++++++
4 files changed, 81 insertions(+)
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 27545496c5..3a3126f267 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
@@ -462,6 +462,24 @@ public class CreateMaterializedViewStmt extends DdlStmt {
if (mvAggregateType == null) {
mvAggregateType =
AggregateType.valueOf(functionName.toUpperCase());
}
+
+ if (!isReplay && defineExpr.hasAggregateSlot()) {
+ SlotRef slot = null;
+ if (defineExpr instanceof SlotRef) {
+ slot = (SlotRef) defineExpr;
+ } else if (defineExpr instanceof CastExpr &&
defineExpr.getChild(0) instanceof SlotRef) {
+ slot = (SlotRef) defineExpr.getChild(0);
+ } else {
+ throw new AnalysisException("Aggregate function require single
slot argument, invalid argument is: "
+ + defineExpr.toSql());
+ }
+
+ AggregateType input = slot.getColumn().getAggregationType();
+ if (!input.equals(mvAggregateType)) {
+ throw new AnalysisException("Aggregate function require same
with slot aggregate type, input: "
+ + input.name() + ", required: " +
mvAggregateType.name());
+ }
+ }
return new MVColumnItem(type, mvAggregateType, defineExpr,
mvColumnBuilder(defineExpr.toSql()));
}
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 a28e0cc7f7..3fea7eb920 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
@@ -2072,6 +2072,15 @@ public abstract class Expr extends TreeNode<Expr>
implements ParseNode, Cloneabl
return false;
}
+ public boolean hasAggregateSlot() {
+ for (Expr expr : children) {
+ if (expr.hasAggregateSlot()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* For excute expr the result is nullable
* TODO: Now only SlotRef and LiteralExpr overwrite the method, each child
of Expr should
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 90cb11f576..967785bdfd 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
@@ -383,6 +383,11 @@ public class SlotRef extends Expr {
return false;
}
+ @Override
+ public boolean hasAggregateSlot() {
+ return desc.getColumn().isAggregated();
+ }
+
@Override
public boolean isRelativedByTupleIds(List<TupleId> tids) {
return isBoundByTupleIds(tids);
diff --git a/regression-test/suites/mv_p0/test_mv_useless/agg_invalid.groovy
b/regression-test/suites/mv_p0/test_mv_useless/agg_invalid.groovy
new file mode 100644
index 0000000000..f4702769ca
--- /dev/null
+++ b/regression-test/suites/mv_p0/test_mv_useless/agg_invalid.groovy
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite ("agg_invalid") {
+ def testTable = "test_agg_mv_useless_table"
+ def getJobState = { tableName ->
+ def jobStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE
TableName='${testTable}' ORDER BY CreateTime DESC LIMIT 1; """
+ return jobStateResult[0][8]
+ }
+ sql """drop table if exists t1;"""
+
+ sql """
+ CREATE TABLE t1 ( p1 INT, p2 INT, p3 INT, v1 INT SUM, v2 INT
MAX, v3 INT MIN ) AGGREGATE KEY (p1, p2, p3) DISTRIBUTED BY HASH (p1) BUCKETS
1 PROPERTIES ('replication_num' = '1');
+ """
+
+ test {
+ sql "CREATE MATERIALIZED VIEW mv_1 AS SELECT p1, SUM(v3) FROM t1 GROUP
BY p1;"
+ exception "errCode = 2,"
+ }
+
+ test {
+ sql "CREATE MATERIALIZED VIEW mv_2 AS SELECT p1, MIN(v3+v3) FROM t1
GROUP BY p1;"
+ exception "errCode = 2,"
+ }
+
+ test {
+ sql "CREATE MATERIALIZED VIEW mv_3 AS SELECT p1, SUM(v1) FROM t1 GROUP
BY p1;"
+ exception null
+ }
+
+ test {
+ sql "CREATE MATERIALIZED VIEW mv_4 AS SELECT p1, SUM(abs(v1)) FROM t1
GROUP BY p1;"
+ exception "errCode = 2,"
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]