[Bug](materialized-view) add limitation for duplicate expr on materialized view (#27523)
add limitation for duplicate expr on materialized view
This commit is contained in:
@ -39,6 +39,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -46,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Materialized view is performed to materialize the results of query.
|
||||
@ -342,19 +344,19 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
}
|
||||
}
|
||||
|
||||
for (Expr groupExpr : groupingExprs) {
|
||||
boolean match = false;
|
||||
String rhs = selectStmt.getExprFromAliasSMap(groupExpr).toSqlWithoutTbl();
|
||||
for (Expr expr : selectExprs) {
|
||||
String lhs = selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
|
||||
if (lhs.equalsIgnoreCase(rhs)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
Set<String> selectExprNames = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
|
||||
for (Expr expr : selectExprs) {
|
||||
String selectExprName = selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
|
||||
if (selectExprNames.contains(selectExprName)) {
|
||||
throw new AnalysisException("The select expr " + selectExprName + " is duplicated.");
|
||||
}
|
||||
selectExprNames.add(selectExprName);
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
throw new AnalysisException("The grouping expr " + rhs + " not in select list.");
|
||||
for (Expr expr : groupingExprs) {
|
||||
String groupExprName = selectStmt.getExprFromAliasSMap(expr).toSqlWithoutTbl();
|
||||
if (!selectExprNames.contains(groupExprName)) {
|
||||
throw new AnalysisException("The grouping expr " + groupExprName + " not in select list.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,4 +41,14 @@ suite ("agg_invalid") {
|
||||
sql "CREATE MATERIALIZED VIEW mv_4 AS SELECT p1, SUM(abs(v1)) FROM t1 GROUP BY p1;"
|
||||
exception "errCode = 2,"
|
||||
}
|
||||
|
||||
test {
|
||||
sql "CREATE MATERIALIZED VIEW mv_5 AS SELECT p1, p2, p1, SUM(v1) FROM t1 GROUP BY p1,p2,p1;"
|
||||
exception "errCode = 2,"
|
||||
}
|
||||
|
||||
test {
|
||||
sql "CREATE MATERIALIZED VIEW mv_5 AS SELECT p1, p2, SUM(v1), SUM(v1) FROM t1 GROUP BY p1,p2;"
|
||||
exception "errCode = 2,"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user