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

[Bug](materialized-view) add limitation for duplicate expr on materialized view #27523

Merged
merged 1 commit into from
Nov 24, 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 @@ -39,13 +39,15 @@
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;

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.
Expand Down Expand Up @@ -342,19 +344,19 @@ private void analyzeGroupByClause() throws AnalysisException {
}
}

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.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,"
}
}