From fa052b1a87d03a89ded4984283f348e6ef71b3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=95=E5=86=B7?= <82279870+TangSiyang2001@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:05:13 +0800 Subject: [PATCH] [fix](Stmt)pre-block create stmt with column type `ALL` (#16757) --- .../doris/analysis/CreateTableStmt.java | 9 +++++- .../doris/analysis/CreateTableStmtTest.java | 10 +++++++ .../suites/ddl_p0/test_create_blocked.groovy | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 regression-test/suites/ddl_p0/test_create_blocked.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java index 1dcdaad20b..dc699cde00 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java @@ -24,6 +24,7 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.Index; import org.apache.doris.catalog.KeysType; import org.apache.doris.catalog.PrimitiveType; +import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; @@ -54,6 +55,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; @@ -322,7 +324,12 @@ public class CreateTableStmt extends DdlStmt { enableUniqueKeyMergeOnWrite = PropertyAnalyzer.analyzeUniqueKeyMergeOnWrite(new HashMap<>(properties)); enableStoreRowColumn = PropertyAnalyzer.analyzeStoreRowColumn(new HashMap<>(properties)); } - + //pre-block creation with column type ALL + for (ColumnDef columnDef : columnDefs) { + if (Objects.equals(columnDef.getType(), Type.ALL)) { + throw new AnalysisException("Disable to create table with `ALL` type columns."); + } + } // analyze key desc if (engineName.equalsIgnoreCase("olap")) { // olap table diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableStmtTest.java index b8f590ab24..b826f5e1e9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableStmtTest.java @@ -43,6 +43,7 @@ import org.junit.rules.ExpectedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -241,6 +242,15 @@ public class CreateTableStmtTest { stmt.analyze(analyzer); } + @Test(expected = AnalysisException.class) + public void testTypeAll() throws UserException { + final ArrayList colAllList = Lists.newArrayList(); + colAllList.add(new ColumnDef("colAll", new TypeDef(ScalarType.createType(PrimitiveType.ALL)))); + CreateTableStmt stmt = new CreateTableStmt(false, false, tblNameNoDb, colAllList, "olap", new KeysDesc(), null, + new RandomDistributionDesc(10), null, null, ""); + stmt.analyze(analyzer); + } + @Test public void testBmpHllKey() throws Exception { diff --git a/regression-test/suites/ddl_p0/test_create_blocked.groovy b/regression-test/suites/ddl_p0/test_create_blocked.groovy new file mode 100644 index 0000000000..40c9fb5d22 --- /dev/null +++ b/regression-test/suites/ddl_p0/test_create_blocked.groovy @@ -0,0 +1,29 @@ +// 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("test_create_blocked") { + try { + sql """ + CREATE TABLE test_create_blocked (c1 all) DISTRIBUTED BY HASH(c1) PROPERTIES('replication_num'='1'); + """ + assertTrue(false, "should not be able to execute") + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("Disable to create table with `ALL` type columns")) + }finally { + sql """ DROP TABLE IF EXISTS test_create_blocked""" + } +} \ No newline at end of file