Skip to content

Commit

Permalink
[Bug](materialized-view) forbid create mv/rollup on mow table (apache…
Browse files Browse the repository at this point in the history
…#20001)

forbid create mv/rollup on mow table
  • Loading branch information
BiteTheDDDDt authored May 25, 2023
1 parent 002c76e commit 6189610
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions conf/asan_suppr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ interceptor_via_fun:doris::FrontendServiceClient::recv_finishTask
interceptor_via_fun:doris::FrontendServiceClient::recv_streamLoadPut
interceptor_via_fun:doris::FrontendService_report_pargs::write
interceptor_via_fun:doris::FrontendServiceClient::recv_loadTxnPreCommit
interceptor_via_fun:doris::ThriftClientImpl::close
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ private List<Column> checkAndPrepareMaterializedView(CreateMaterializedViewStmt
if (olapTable.hasMaterializedIndex(addMVClause.getMVName())) {
throw new DdlException("Materialized view[" + addMVClause.getMVName() + "] already exists");
}
if (olapTable.getEnableUniqueKeyMergeOnWrite()) {
throw new DdlException("MergeOnWrite table can't create materialized view.");
}
// check if mv columns are valid
// a. Aggregate or Unique table:
// 1. For aggregate table, mv columns with aggregate function should be same as base schema
Expand Down Expand Up @@ -594,6 +597,9 @@ private List<Column> checkAndPrepareMaterializedView(CreateMaterializedViewStmt
public List<Column> checkAndPrepareMaterializedView(AddRollupClause addRollupClause, OlapTable olapTable,
long baseIndexId, boolean changeStorageFormat)
throws DdlException {
if (olapTable.getEnableUniqueKeyMergeOnWrite()) {
throw new DdlException("MergeOnWrite table can't create materialized view.");
}
String rollupIndexName = addRollupClause.getRollupName();
List<String> rollupColumnNames = addRollupClause.getColumnNames();
if (changeStorageFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static void beforeClass() throws Exception {
+ "PARTITION BY RANGE(k1)\n" + "(\n"
+ " PARTITION p1 values less than('2020-02-01 00:00:00'),\n"
+ " PARTITION p2 values less than('2020-03-01 00:00:00')\n" + ")\n"
+ "DISTRIBUTED BY HASH(k2) BUCKETS 3\n" + "PROPERTIES('replication_num' = '1');");
+ "DISTRIBUTED BY HASH(k2) BUCKETS 3\n" + "PROPERTIES('replication_num' = '1','enable_unique_key_merge_on_write' = 'false');");

createTable("create external table test.odbc_table\n" + "( `k1` bigint(20) COMMENT \"\",\n"
+ " `k2` datetime COMMENT \"\",\n" + " `k3` varchar(20) COMMENT \"\",\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,13 @@ public void testWindowsFunctionInQuery() throws Exception {
@Test
public void testUniqueTableInQuery() throws Exception {
String uniqueTable = "CREATE TABLE " + TEST_TABLE_NAME + " (k1 int, k2 int, v1 int) UNIQUE KEY (k1, k2) "
+ "DISTRIBUTED BY HASH(k1) BUCKETS 3 PROPERTIES ('replication_num' = '1');";
+ "DISTRIBUTED BY HASH(k1) BUCKETS 3 PROPERTIES ('replication_num' = '1','enable_unique_key_merge_on_write' = 'false');";
createTable(uniqueTable);
String createK1MV = "create materialized view only_k1 as select k2 from " + TEST_TABLE_NAME + " group by "
+ "k2;";
createMv(createK1MV);
String query = "select * from " + TEST_TABLE_NAME + ";";
singleTableTest(query, TEST_TABLE_NAME, true);
singleTableTest(query, TEST_TABLE_NAME, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public void testWindowsFunctionInQuery() throws Exception {
@Test
public void testUniqueTableInQuery() throws Exception {
String uniqueTable = "CREATE TABLE " + TEST_TABLE_NAME + " (k1 int, k2 int, v1 int) UNIQUE KEY (k1, k2) "
+ "DISTRIBUTED BY HASH(k1) BUCKETS 3 PROPERTIES ('replication_num' = '1');";
+ "DISTRIBUTED BY HASH(k1) BUCKETS 3 PROPERTIES ('replication_num' = '1', 'enable_unique_key_merge_on_write' = 'false');";
dorisAssert.withTable(uniqueTable);
String createK1K2MV = "create materialized view only_k1 as select k2, k1 from " + TEST_TABLE_NAME + " group by "
+ "k2, k1;";
Expand Down
40 changes: 40 additions & 0 deletions regression-test/suites/mv_p0/test_mv_useless/mow_invalid.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 ("mow_invalid") {
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,k3)
distributed BY hash(k1) buckets 3
properties(
"replication_num" = "1",
"enable_unique_key_merge_on_write" = "true"
);
"""

test {
sql "create materialized view k123p as select k1,k2+k3 from u_table;"
exception "errCode = 2,"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ suite ("test_uniq_mv_schema_change") {
`min_dwell_time` INT DEFAULT "99999" COMMENT "用户最小停留时间")
UNIQUE KEY(`user_id`, `date`, `city`, `age`, `sex`) DISTRIBUTED BY HASH(`user_id`)
BUCKETS 1
PROPERTIES ( "replication_num" = "1", "light_schema_change" = "false");
PROPERTIES ( "replication_num" = "1", "light_schema_change" = "false", 'enable_unique_key_merge_on_write' = 'false');
"""

sql """ INSERT INTO ${tableName} VALUES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ suite ("test_uniq_rollup_schema_change") {
`min_dwell_time` INT DEFAULT "99999" COMMENT "用户最小停留时间")
UNIQUE KEY(`user_id`, `date`, `city`, `age`, `sex`) DISTRIBUTED BY HASH(`user_id`)
BUCKETS 1
PROPERTIES ( "replication_num" = "1", "light_schema_change" = "false" );
PROPERTIES ( "replication_num" = "1", "light_schema_change" = "false", 'enable_unique_key_merge_on_write' = 'false');
"""

sql """ INSERT INTO ${tableName} VALUES
Expand Down

0 comments on commit 6189610

Please sign in to comment.