This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 603f4ab20f [fix](truncate) it will directly return and avoid throwing
IllegalStateException caused by bufferSize equals zero when table has no
partition (#21378)
603f4ab20f is described below
commit 603f4ab20f9a79db64c4993daa6fbc481bab58a5
Author: htyoung <[email protected]>
AuthorDate: Sat Jul 1 08:39:38 2023 +0800
[fix](truncate) it will directly return and avoid throwing
IllegalStateException caused by bufferSize equals zero when table has no
partition (#21378)
if table currently has no partition, the truncate SQL will be a empty
command, it should directly return and avoid throwing IllegalStateException
caused by bufferSize equals zero
Issue Number: close #21316
Co-authored-by: tongyang.han <[email protected]>
---
.../apache/doris/datasource/InternalCatalog.java | 9 ++-
.../suites/ddl_p0/test_truncate_table1.groovy | 78 ++++++++++++++++++++++
2 files changed, 85 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index 043b46366b..221d36695a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -1871,7 +1871,7 @@ public class InternalCatalog implements
CatalogIf<Database> {
// create columns
List<Column> baseSchema = stmt.getColumns();
validateColumns(baseSchema, isKeysRequired);
- checkAutoIncColummns(baseSchema, keysType);
+ checkAutoIncColumns(baseSchema, keysType);
// analyze replica allocation
ReplicaAllocation replicaAlloc =
PropertyAnalyzer.analyzeReplicaAllocation(stmt.getProperties(), "");
@@ -2643,7 +2643,7 @@ public class InternalCatalog implements
CatalogIf<Database> {
/*
* check column's auto increment property
*/
- private void checkAutoIncColummns(List<Column> columns, KeysType type)
throws DdlException {
+ private void checkAutoIncColumns(List<Column> columns, KeysType type)
throws DdlException {
boolean encounterAutoIncColumn = false;
for (Column column : columns) {
if (column.isAutoInc()) {
@@ -2710,6 +2710,11 @@ public class InternalCatalog implements
CatalogIf<Database> {
partitionsDistributionInfo.put(partition.getId(),
partition.getDistributionInfo());
}
}
+ // if table currently has no partitions, this sql like empty
command and do nothing, should return directly
+ // at the same time, it will avoid throwing IllegalStateException
when `bufferSize` equals zero
+ if (origPartitions.isEmpty()) {
+ return;
+ }
copiedTbl = olapTable.selectiveCopy(origPartitions.keySet(),
IndexExtState.VISIBLE, false);
} finally {
olapTable.readUnlock();
diff --git a/regression-test/suites/ddl_p0/test_truncate_table1.groovy
b/regression-test/suites/ddl_p0/test_truncate_table1.groovy
new file mode 100644
index 0000000000..7f25dca5ae
--- /dev/null
+++ b/regression-test/suites/ddl_p0/test_truncate_table1.groovy
@@ -0,0 +1,78 @@
+// 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_truncate_table1") {
+ // test truncate partition table which has no partition
+ def testTable = "test_truncate_no_partition_table"
+ sql "DROP TABLE IF EXISTS ${testTable}"
+ sql """
+ CREATE TABLE ${testTable}
+ (
+ k1 DATE,
+ k2 DECIMAL(10, 2) DEFAULT "10.5",
+ k3 CHAR(10) COMMENT "string column",
+ k4 INT NOT NULL DEFAULT "1" COMMENT "int column"
+ )
+ PARTITION BY RANGE(k1)
+ ()
+ DISTRIBUTED BY HASH(k2) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+ """
+ List<List<Object>> result = sql "show partitions from ${testTable}"
+ logger.info("${result}")
+ assertEquals(result.size(), 0)
+
+ sql """truncate table ${testTable};"""
+ result = sql "show partitions from ${testTable}"
+ logger.info("${result}")
+ assertEquals(result.size(), 0)
+
+ sql "DROP TABLE IF EXISTS ${testTable}"
+
+
+
+ // test truncate non partition table
+ def testNonPartitionTable = "test_truncate_non_partition_table"
+ sql "DROP TABLE IF EXISTS ${testNonPartitionTable}"
+ sql """
+ CREATE TABLE ${testNonPartitionTable}
+ (
+ k1 DATE,
+ k2 DECIMAL(10, 2) DEFAULT "10.5",
+ k3 CHAR(10) COMMENT "string column",
+ k4 INT NOT NULL DEFAULT "1" COMMENT "int column"
+ )
+ DISTRIBUTED BY HASH(k2) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+ """
+ List<List<Object>> result1 = sql "show partitions from
${testNonPartitionTable}"
+ logger.info("${result1}")
+ assertEquals(result1.size(), 1)
+
+ sql """truncate table ${testNonPartitionTable};"""
+ result1 = sql "show partitions from ${testNonPartitionTable}"
+ logger.info("${result1}")
+ assertEquals(result1.size(), 1)
+
+ sql "DROP TABLE IF EXISTS ${testNonPartitionTable}"
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]