diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java index 4f7f5cb96e..810cbf835e 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java @@ -382,13 +382,13 @@ public abstract class Type { // 3. don't support group by // 4. don't support index public boolean isOnlyMetricType() { - return isObjectStored() || isComplexType(); + return isObjectStored() || isComplexType() || isJsonbType(); } public static final String OnlyMetricTypeErrorMsg = - "Doris hll, bitmap, array, map, struct column must use with specific function, and don't" + "Doris hll, bitmap, array, map, struct, jsonb column must use with specific function, and don't" + " support filter or group by. please run 'help hll' or 'help bitmap' or 'help array'" - + " or 'help map' or 'help struct' in your mysql client."; + + " or 'help map' or 'help struct' or 'help jsonb' in your mysql client."; public boolean isHllType() { return isScalarType(PrimitiveType.HLL); diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java b/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java index f6fc944c92..5b1df46e6e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java @@ -560,7 +560,7 @@ public class MaterializedViewHandler extends AlterHandler { } // if the column is complex type, we forbid to create materialized view for (Column column : newMVColumns) { - if (column.getDataType().isComplexType()) { + if (column.getDataType().isComplexType() || column.getDataType().isJsonbType()) { throw new DdlException("The " + column.getDataType() + " column[" + column + "] not support " + "to create materialized view"); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java index 4c003cf283..4a8f642760 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java @@ -65,7 +65,7 @@ public class CheckExpressionLegalityTest implements MemoPatternMatchSupported { )); ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, - "Doris hll, bitmap, array, map, struct column must use with specific function", () -> + "column must use with specific function", () -> PlanChecker.from(connectContext) .analyze("select count(distinct id) from (select to_bitmap(1) id) tbl") .applyBottomUp(new ExpressionRewrite(CheckLegalityAfterRewrite.INSTANCE)) diff --git a/regression-test/data/materialized_view_p0/test_create_mv_datatype.out b/regression-test/data/materialized_view_p0/test_create_mv_datatype.out new file mode 100644 index 0000000000..4b64da148b --- /dev/null +++ b/regression-test/data/materialized_view_p0/test_create_mv_datatype.out @@ -0,0 +1,31 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_desc1 -- +base_table DUP_KEYS c_int INT Yes true \N true + c_bigint BIGINT Yes false \N NONE true + c_float BIGINT Yes false \N NONE true + c_jsonb JSONB Yes false \N NONE true + c_array ARRAY Yes false \N NONE true + c_map MAP Yes false \N NONE true + c_struct STRUCT Yes false \N NONE true + +mv1 DUP_KEYS c_bigint BIGINT Yes true \N true + c_int INT Yes true \N true + c_float BIGINT Yes true \N true + +-- !select_desc2 -- +base_table DUP_KEYS c_int INT Yes true \N true + c_bigint BIGINT Yes false \N NONE true + c_float BIGINT Yes false \N NONE true + c_jsonb JSONB Yes false \N NONE true + c_array ARRAY Yes false \N NONE true + c_map MAP Yes false \N NONE true + c_struct STRUCT Yes false \N NONE true + +mv1 DUP_KEYS c_bigint BIGINT Yes true \N true + c_int INT Yes true \N true + c_float BIGINT Yes true \N true + +mv2 DUP_KEYS c_bigint BIGINT Yes true \N true + c_int INT Yes true \N true + c_jsonb JSONB Yes false \N NONE true + diff --git a/regression-test/suites/materialized_view_p0/test_create_mv_complex_type.groovy b/regression-test/suites/materialized_view_p0/test_create_mv_complex_type.groovy new file mode 100644 index 0000000000..a689649c3e --- /dev/null +++ b/regression-test/suites/materialized_view_p0/test_create_mv_complex_type.groovy @@ -0,0 +1,205 @@ +// 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.codehaus.groovy.runtime.IOGroovyMethods + +suite ("create_mv_complex_type") { + def wait_for_create_mv_finish = { table_name, OpTimeout -> + def delta_time = 1000 + for(useTime = 0; useTime <= OpTimeout; useTime += delta_time){ + alter_res = sql """SHOW ALTER TABLE MATERIALIZED VIEW WHERE TableName = "${table_name}" ORDER BY CreateTime DESC LIMIT 1;""" + alter_res = alter_res.toString() + if(alter_res.contains("FINISHED")) { + break + } + sleep(delta_time) + } + assertTrue(useTime <= OpTimeout, "wait_for_create_mv_finish timeout") + } + + sql "ADMIN SET FRONTEND CONFIG ('enable_struct_type' = 'true')" + sql "ADMIN SET FRONTEND CONFIG ('enable_map_type' = 'true')" + + sql """ DROP TABLE IF EXISTS base_table; """ + sql """ + create table base_table ( + c_int INT, + c_bigint BIGINT(10), + c_float BIGINT, + c_jsonb JSONB, + c_array ARRAY, + c_map MAP, + c_struct STRUCT + ) + duplicate key (c_int) + distributed BY hash(c_int) buckets 3 + properties("replication_num" = "1"); + """ + + sql """insert into base_table select 1, 100000, 1.0, '{"jsonk1": 123}', [100, 200], {"k1": 10}, {1, 2};""" + + def success = false + + // 1. special column - mv dup key + success = false + try { + sql """create materialized view mv as select c_jsonb, c_int from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_jsonb from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_array, c_int from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_array from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_map, c_int from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_map from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_struct, c_int from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_struct from base_table;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("not support to create materialized view"), e.getMessage()) + } + assertFalse(success) + + + // 2. special column - mv agg key + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_jsonb, count(c_bigint) from base_table group by c_bigint, c_int, c_jsonb;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_array, count(c_bigint) from base_table group by c_bigint, c_int, c_array;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_map, count(c_bigint) from base_table group by c_bigint, c_int, c_map;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_struct, count(c_bigint) from base_table group by c_bigint, c_int, c_struct;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + + // 3. special column - ORDER BY + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_jsonb from base_table order by c_bigint, c_int, c_jsonb;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_array from base_table order by c_bigint, c_int, c_array;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_map from base_table order by c_bigint, c_int, c_map;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) + + success = false + try { + sql """create materialized view mv as select c_bigint, c_int, c_struct from base_table order by c_bigint, c_int, c_struct;""" + success = true + } catch (Exception e) { + assertTrue(e.getMessage().contains("don't support filter or group by"), e.getMessage()) + } + assertFalse(success) +}