From 9efc7b63ec91d99e1efd46d50a79fec27df4600a Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 6 Jun 2024 22:53:08 +0800 Subject: [PATCH] [fix](mtmv)Mtmv support row column (#35860) (#35956) pick from master: #35860 --- .../plans/commands/info/CreateMTMVInfo.java | 13 ++++ .../data/mtmv_p0/test_row_column_mtmv.out | 13 ++++ .../mtmv_p0/test_row_column_mtmv.groovy | 72 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 regression-test/data/mtmv_p0/test_row_column_mtmv.out create mode 100644 regression-test/suites/mtmv_p0/test_row_column_mtmv.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java index 0add620d03..aeb109726e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java @@ -34,6 +34,7 @@ import org.apache.doris.catalog.View; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.FeNameFormat; import org.apache.doris.common.util.DynamicPartitionUtil; +import org.apache.doris.common.util.PropertyAnalyzer; import org.apache.doris.mtmv.EnvInfo; import org.apache.doris.mtmv.MTMVPartitionInfo; import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType; @@ -335,6 +336,18 @@ public class CreateMTMVInfo { CollectionUtils.isEmpty(simpleColumnDefinitions) ? null : simpleColumnDefinitions.get(i).getComment())); } + // add a hidden column as row store + if (properties != null) { + try { + boolean storeRowColumn = + PropertyAnalyzer.analyzeStoreRowColumn(Maps.newHashMap(properties)); + if (storeRowColumn) { + columns.add(ColumnDefinition.newRowStoreColumnDefinition(null)); + } + } catch (Exception e) { + throw new AnalysisException(e.getMessage(), e.getCause()); + } + } } /** diff --git a/regression-test/data/mtmv_p0/test_row_column_mtmv.out b/regression-test/data/mtmv_p0/test_row_column_mtmv.out new file mode 100644 index 0000000000..8f9122aa75 --- /dev/null +++ b/regression-test/data/mtmv_p0/test_row_column_mtmv.out @@ -0,0 +1,13 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !k1 -- +1 1 + +-- !k2 -- +3 3 + +-- !k1_k2 -- +1 1 + +-- !k2_k1 -- +1 1 + diff --git a/regression-test/suites/mtmv_p0/test_row_column_mtmv.groovy b/regression-test/suites/mtmv_p0/test_row_column_mtmv.groovy new file mode 100644 index 0000000000..646fdcde07 --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_row_column_mtmv.groovy @@ -0,0 +1,72 @@ +// 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. + +import org.junit.Assert; + +suite("test_row_column_mtmv","mtmv") { + String suiteName = "test_row_column_mtmv" + String tableName = "${suiteName}_table" + String mvName = "${suiteName}_mv" + sql """drop table if exists `${tableName}`""" + sql """drop materialized view if exists ${mvName};""" + + sql """ + CREATE TABLE ${tableName} + ( + k1 TINYINT, + k2 INT not null + ) + COMMENT "my first table" + DISTRIBUTED BY HASH(k2) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + insert into ${tableName} values(1,1),(2,2),(3,3); + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1', + 'store_row_column' = 'true' + ) + AS + SELECT * from ${tableName}; + """ + + sql """ + REFRESH MATERIALIZED VIEW ${mvName} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName) + + order_qt_k1 "SELECT * FROM ${mvName} order by k1 limit 1" + order_qt_k2 "SELECT * FROM ${mvName} order by k2 desc limit 1" + order_qt_k1_k2 "SELECT * FROM ${mvName} order by k1,k2 limit 1" + order_qt_k2_k1 "SELECT * FROM ${mvName} order by k2,k1 limit 1" + + sql """SET show_hidden_columns=true;""" + def colRes = sql """desc ${mvName};""" + logger.info("colRes: " + colRes.toString()) + assertTrue(colRes.toString().contains("__DORIS_ROW_STORE_COL__")) + + sql """SET show_hidden_columns=false;""" + sql """drop table if exists `${tableName}`""" + sql """drop materialized view if exists ${mvName};""" +}