Skip to content
Open
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 @@ -225,7 +225,7 @@ public void analyze(Analyzer analyzer) throws UserException {
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());
Expand Down Expand Up @@ -582,7 +582,7 @@ private MVColumnItem buildMVColumnItem(Analyzer analyzer, FunctionCallExpr funct
mvAggregateType = AggregateType.valueOf(functionName.toUpperCase());
}

if (!isReplay && defineExpr.hasAggregateSlot()) {
if (!isReplay && defineExpr.hasAggregateSlot(getMVKeysType())) {
SlotRef slot = null;
if (defineExpr instanceof SlotRef) {
slot = (SlotRef) defineExpr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -2271,9 +2272,9 @@ protected static boolean hasNullableChild(List<Expr> children) {
return false;
}

public boolean hasAggregateSlot() {
public boolean hasAggregateSlot(KeysType keysType) {
for (Expr expr : children) {
if (expr.hasAggregateSlot()) {
if (expr.hasAggregateSlot(keysType)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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;
Expand Down Expand Up @@ -499,7 +500,13 @@ public boolean isBoundByTupleIds(List<TupleId> tids) {
}

@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();
}

Expand Down
23 changes: 23 additions & 0 deletions regression-test/suites/mv_p0/where/k123/k123.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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;""")
}
Loading