From dacf06a1ff72ecf3b6ad93d78a6207853353aae3 Mon Sep 17 00:00:00 2001 From: yujun Date: Wed, 7 Aug 2024 09:46:21 +0800 Subject: [PATCH 1/4] [fix](create table) fix nereids create table no check buckets=0 (#38971) Fix: nereids create table no check buckets=0 --- .../commands/info/DistributionDescriptor.java | 3 ++ .../table_p0/test_table_with_buckets.groovy | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 regression-test/suites/table_p0/test_table_with_buckets.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DistributionDescriptor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DistributionDescriptor.java index 86b158a9e06ad1..056bfd20897f19 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DistributionDescriptor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DistributionDescriptor.java @@ -72,6 +72,9 @@ public void updateBucketNum(int bucketNum) { * analyze distribution descriptor */ public void validate(Map columnMap, KeysType keysType) { + if (bucketNum <= 0) { + throw new AnalysisException("Buckets number of distribution should be greater than zero."); + } if (isHash) { Set colSet = Sets.newHashSet(cols); if (colSet.size() != cols.size()) { diff --git a/regression-test/suites/table_p0/test_table_with_buckets.groovy b/regression-test/suites/table_p0/test_table_with_buckets.groovy new file mode 100644 index 00000000000000..efec750839de3a --- /dev/null +++ b/regression-test/suites/table_p0/test_table_with_buckets.groovy @@ -0,0 +1,53 @@ +// 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_table_with_buckets') { + def tbl1 = 'test_table_with_buckets_tbl1' + def tbl2 = 'test_table_with_buckets_tbl2' + sql "drop table if exists `${tbl1}`" + sql "drop table if exists `${tbl2}`" + try { + test { + sql "create table ${tbl1}(k int) distributed by hash(k) buckets 0 properties('replication_num' = '1')" + exception 'Buckets number of distribution should be greater than zero.' + } + + test { + sql """ + CREATE TABLE IF NOT EXISTS ${tbl2} ( k1 date NOT NULL, k2 varchar(20) NOT NULL, k3 int sum NOT NULL ) + AGGREGATE KEY(k1,k2) + PARTITION BY RANGE(k1) ( ) + DISTRIBUTED BY HASH(k1) BUCKETS 3 + PROPERTIES ( + "dynamic_partition.enable"="true", + "dynamic_partition.end"="3", + "dynamic_partition.buckets"="0", + "dynamic_partition.start"="-3", + "dynamic_partition.prefix"="p", + "dynamic_partition.time_unit"="DAY", + "dynamic_partition.create_history_partition"="true", + "dynamic_partition.replication_allocation" = "tag.location.default: 1" + ) + """ + + exception 'Dynamic partition buckets must greater than 0' + } + } finally { + sql "drop table if exists `${tbl1}`" + sql "drop table if exists `${tbl2}`" + } +} From a2cc67ae9c0ec6de6da01b6a8247dcec6a14f348 Mon Sep 17 00:00:00 2001 From: yujun777 Date: Wed, 7 Aug 2024 11:57:13 +0800 Subject: [PATCH 2/4] update --- .../suites/table_p0/test_table_with_buckets.groovy | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/regression-test/suites/table_p0/test_table_with_buckets.groovy b/regression-test/suites/table_p0/test_table_with_buckets.groovy index efec750839de3a..b61228aa6d7657 100644 --- a/regression-test/suites/table_p0/test_table_with_buckets.groovy +++ b/regression-test/suites/table_p0/test_table_with_buckets.groovy @@ -15,15 +15,21 @@ // specific language governing permissions and limitations // under the License. -suite('test_table_with_buckets') { +suite('test_table_with_buckets', 'nonConcurrent') { def tbl1 = 'test_table_with_buckets_tbl1' def tbl2 = 'test_table_with_buckets_tbl2' sql "drop table if exists `${tbl1}`" sql "drop table if exists `${tbl2}`" try { - test { - sql "create table ${tbl1}(k int) distributed by hash(k) buckets 0 properties('replication_num' = '1')" - exception 'Buckets number of distribution should be greater than zero.' + def bak_enable_nereids_planner = sql_return_maparray("show variables like 'enable_nereids_planner'")[0].Value + try { + sql 'set enable_nereids_planner = true' + test { + sql "create table ${tbl1}(k int) distributed by hash(k) buckets 0 properties('replication_num' = '1')" + exception 'Buckets number of distribution should be greater than zero.' + } + } finally { + sql "set enable_nereids_planner = ${bak_enable_nereids_planner}" } test { From d5fc863da45fef44cc4bbf8925f6d75413fc467d Mon Sep 17 00:00:00 2001 From: yujun777 Date: Wed, 7 Aug 2024 12:01:19 +0800 Subject: [PATCH 3/4] update --- .../table_p0/test_table_with_buckets.groovy | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/regression-test/suites/table_p0/test_table_with_buckets.groovy b/regression-test/suites/table_p0/test_table_with_buckets.groovy index b61228aa6d7657..d31158aa88a125 100644 --- a/regression-test/suites/table_p0/test_table_with_buckets.groovy +++ b/regression-test/suites/table_p0/test_table_with_buckets.groovy @@ -20,16 +20,14 @@ suite('test_table_with_buckets', 'nonConcurrent') { def tbl2 = 'test_table_with_buckets_tbl2' sql "drop table if exists `${tbl1}`" sql "drop table if exists `${tbl2}`" + + def bak_enable_nereids_planner = sql_return_maparray("show variables like 'enable_nereids_planner'")[0].Value + sql 'set enable_nereids_planner = true' + try { - def bak_enable_nereids_planner = sql_return_maparray("show variables like 'enable_nereids_planner'")[0].Value - try { - sql 'set enable_nereids_planner = true' - test { - sql "create table ${tbl1}(k int) distributed by hash(k) buckets 0 properties('replication_num' = '1')" - exception 'Buckets number of distribution should be greater than zero.' - } - } finally { - sql "set enable_nereids_planner = ${bak_enable_nereids_planner}" + test { + sql "create table ${tbl1}(k int) distributed by hash(k) buckets 0 properties('replication_num' = '1')" + exception 'Buckets number of distribution should be greater than zero.' } test { @@ -53,6 +51,7 @@ suite('test_table_with_buckets', 'nonConcurrent') { exception 'Dynamic partition buckets must greater than 0' } } finally { + sql "set enable_nereids_planner = ${bak_enable_nereids_planner}" sql "drop table if exists `${tbl1}`" sql "drop table if exists `${tbl2}`" } From 893df16a476af988233f15f422c0463a80b1020a Mon Sep 17 00:00:00 2001 From: yujun777 Date: Fri, 9 Aug 2024 12:46:29 +0800 Subject: [PATCH 4/4] update --- .../suites/table_p0/test_table_with_buckets.groovy | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/regression-test/suites/table_p0/test_table_with_buckets.groovy b/regression-test/suites/table_p0/test_table_with_buckets.groovy index d31158aa88a125..45c73bf7e7f498 100644 --- a/regression-test/suites/table_p0/test_table_with_buckets.groovy +++ b/regression-test/suites/table_p0/test_table_with_buckets.groovy @@ -15,19 +15,16 @@ // specific language governing permissions and limitations // under the License. -suite('test_table_with_buckets', 'nonConcurrent') { +suite('test_table_with_buckets') { def tbl1 = 'test_table_with_buckets_tbl1' def tbl2 = 'test_table_with_buckets_tbl2' sql "drop table if exists `${tbl1}`" sql "drop table if exists `${tbl2}`" - def bak_enable_nereids_planner = sql_return_maparray("show variables like 'enable_nereids_planner'")[0].Value - sql 'set enable_nereids_planner = true' - try { test { sql "create table ${tbl1}(k int) distributed by hash(k) buckets 0 properties('replication_num' = '1')" - exception 'Buckets number of distribution should be greater than zero.' + exception 'distribution should be greater than zero' } test { @@ -51,7 +48,6 @@ suite('test_table_with_buckets', 'nonConcurrent') { exception 'Dynamic partition buckets must greater than 0' } } finally { - sql "set enable_nereids_planner = ${bak_enable_nereids_planner}" sql "drop table if exists `${tbl1}`" sql "drop table if exists `${tbl2}`" }