Skip to content

Commit

Permalink
[fix](schema-change) fix the bug of handling empty blocks in schema c…
Browse files Browse the repository at this point in the history
  • Loading branch information
luwei16 authored and weixingyu12 committed Mar 22, 2024
1 parent f365c5e commit 9d01fcc
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
12 changes: 10 additions & 2 deletions be/src/olap/schema_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ Status VSchemaChangeDirectly::_inner_process(RowsetReaderSharedPtr rowset_reader
auto st = rowset_reader->next_block(ref_block.get());
if (!st) {
if (st.is<ErrorCode::END_OF_FILE>()) {
eof = true;
if (ref_block->rows() == 0) {
break;
} else {
eof = true;
}
} else {
return st;
}
Expand Down Expand Up @@ -567,7 +571,11 @@ Status VSchemaChangeWithSorting::_inner_process(RowsetReaderSharedPtr rowset_rea
auto st = rowset_reader->next_block(ref_block.get());
if (!st) {
if (st.is<ErrorCode::END_OF_FILE>()) {
eof = true;
if (ref_block->rows() == 0) {
break;
} else {
eof = true;
}
} else {
return st;
}
Expand Down
83 changes: 83 additions & 0 deletions regression-test/suites/mv_p0/test_create_mv/test_create_mv.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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.

// The cases is copied from https://github.com/trinodb/trino/tree/master
// /testing/trino-product-tests/src/main/resources/sql-tests/testcases
// and modified by Doris.

suite("test_create_mv") {
def tableName = "test_mv_10010"

def getJobState = { table ->
def jobStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE TableName='${table}' ORDER BY CreateTime DESC LIMIT 1; """
return jobStateResult[0][8]
}

sql """ DROP TABLE IF EXISTS ${tableName} """

sql """
CREATE TABLE ${tableName} (
`load_time` datetime NOT NULL COMMENT '事件发生时间',
`id` varchar(192) NOT NULL COMMENT '',
`class` varchar(192) NOT NULL COMMENT '',
`result` int NOT NULL COMMENT ''
) ENGINE=OLAP
DUPLICATE KEY(`load_time`,`id`, `class`)
COMMENT ''
PARTITION BY RANGE(`load_time`)(
PARTITION p1 VALUES LESS THAN ("2025-01-01 00:00:00")
)
DISTRIBUTED BY HASH(`load_time`,`id`, `class`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """ insert into ${tableName} values ('2024-03-20 10:00:00', 'a', 'b', 1) """

sql """
create materialized view mv_1 as
select
date_trunc(load_time, 'minute'),
id,
class,
count(id) as total,
min(result) as min_result,
sum(result) as max_result
from
${tableName}
group by date_trunc(load_time, 'minute'), id, class;
"""

sql """ SHOW ALTER TABLE MATERIALIZED VIEW """

max_try_secs = 60
while (max_try_secs--) {
String res = getJobState(tableName)
if (res == "FINISHED" || res == "CANCELLED") {
assertEquals("FINISHED", res)
sleep(3000)
break
} else {
Thread.sleep(2000)
if (max_try_secs < 1) {
println "test timeout," + "state:" + res
assertEquals("FINISHED",res)
}
}
}
}

0 comments on commit 9d01fcc

Please sign in to comment.