This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new f5f629304b [fix](truncate) fix bug that truncate partition throw NPE
(#9339)
f5f629304b is described below
commit f5f629304b8f58738c51fbdca00a68f9098771e7
Author: Mingyu Chen <[email protected]>
AuthorDate: Sun May 1 18:26:56 2022 +0800
[fix](truncate) fix bug that truncate partition throw NPE (#9339)
1. partition name is case insensitive.
2. add a simple help-resource.zip to help pass the FE ut.
---
.gitignore | 1 -
.../java/org/apache/doris/catalog/Catalog.java | 2 +-
.../java/org/apache/doris/catalog/OlapTable.java | 6 ++-
.../org/apache/doris/common/CaseSensibility.java | 2 +-
.../apache/doris/catalog/TruncateTableTest.java | 41 +++++++++++++++++++++
fe/fe-core/src/test/resources/help-resource.zip | Bin 0 -> 1056 bytes
6 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index aed8a347ba..9a42e446d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,6 @@
*.iml
*.swp
*.jar
-*.zip
*.gz
*.log
*.so.tmp
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
index dd89a77a94..d0cab71cad 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
@@ -6814,7 +6814,7 @@ public class Catalog {
// check partitions
for (Map.Entry<String, Long> entry : origPartitions.entrySet()) {
Partition partition = copiedTbl.getPartition(entry.getValue());
- if (partition == null ||
!partition.getName().equals(entry.getKey())) {
+ if (partition == null ||
!partition.getName().equalsIgnoreCase(entry.getKey())) {
throw new DdlException("Partition [" + entry.getKey() + "]
is changed");
}
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index e108fb82d7..c7795d5e27 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -1286,11 +1286,13 @@ public class OlapTable extends Table {
return copied;
}
- Set<String> partNames = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
+ Set<String> partNames = Sets.newHashSet();
partNames.addAll(copied.getPartitionNames());
+ // partition name is case insensitive:
+ Set<String> lowerReservedPartitionNames =
reservedPartitions.stream().map(String::toLowerCase).collect(Collectors.toSet());
for (String partName : partNames) {
- if (!reservedPartitions.contains(partName)) {
+ if (!lowerReservedPartitionNames.contains(partName.toLowerCase()))
{
copied.dropPartitionAndReserveTablet(partName);
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/common/CaseSensibility.java
b/fe/fe-core/src/main/java/org/apache/doris/common/CaseSensibility.java
index ebd7b63b5b..d0545a14dd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/CaseSensibility.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/CaseSensibility.java
@@ -22,7 +22,7 @@ public enum CaseSensibility {
DATABASE(true),
TABLE(true),
ROLLUP(true),
- PARTITION(true),
+ PARTITION(false),
COLUMN(false),
USER(true),
ROLE(false),
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/TruncateTableTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/TruncateTableTest.java
index db8951da4e..80aec2011f 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/TruncateTableTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/TruncateTableTest.java
@@ -56,6 +56,24 @@ public class TruncateTableTest {
"properties('replication_num' = '1');";
createDb(createDbStmtStr);
createTable(createTableStr);
+
+ String createTable2 = "CREATE TABLE test.case_sensitive_table (\n" +
+ " `date_id` date NULL COMMENT \"\",\n" +
+ " `column2` tinyint(4) NULL COMMENT \"\"\n" +
+ ") ENGINE=OLAP\n" +
+ "DUPLICATE KEY(`date_id`, `column2`)\n" +
+ "COMMENT \"OLAP\"\n" +
+ "PARTITION BY RANGE(`date_id`)\n" +
+ "(\n" +
+ "PARTITION p20211006 VALUES [('2021-10-06'),
('2021-10-07')),\n" +
+ "PARTITION P20211007 VALUES [('2021-10-07'),
('2021-10-08')),\n" +
+ "PARTITION P20211008 VALUES [('2021-10-08'),
('2021-10-09')))\n" +
+ "DISTRIBUTED BY HASH(`column2`) BUCKETS 1\n" +
+ "PROPERTIES (\n" +
+ "\"replication_allocation\" = \"tag.location.default: 1\"\n" +
+ ");";
+
+ createTable(createTable2);
}
@AfterClass
@@ -64,6 +82,29 @@ public class TruncateTableTest {
file.delete();
}
+ @Test
+ public void testTruncateWithCaseInsensitivePartitionName() throws
Exception {
+ Database db =
Catalog.getCurrentCatalog().getDbNullable("default_cluster:test");
+ OlapTable tbl = db.getOlapTableOrDdlException("case_sensitive_table");
+ long p20211006Id = tbl.getPartition("P20211006").getId();
+ long p20211007Id = tbl.getPartition("P20211007").getId();
+ long p20211008Id = tbl.getPartition("p20211008").getId();
+ // truncate p20211008(real name is P20211008)
+ String truncateStr = "TRUNCATE TABLE test.case_sensitive_table
PARTITION p20211008; \n";
+ TruncateTableStmt truncateTableStmt = (TruncateTableStmt)
UtFrameUtils.parseAndAnalyzeStmt(truncateStr, connectContext);
+ Catalog.getCurrentCatalog().truncateTable(truncateTableStmt);
+ Assert.assertNotEquals(p20211008Id,
tbl.getPartition("p20211008").getId());
+ // 2. truncate P20211007
+ truncateStr = "TRUNCATE TABLE test.case_sensitive_table PARTITION
P20211007; \n";
+ truncateTableStmt = (TruncateTableStmt)
UtFrameUtils.parseAndAnalyzeStmt(truncateStr, connectContext);
+ Catalog.getCurrentCatalog().truncateTable(truncateTableStmt);
+ Assert.assertEquals(3, tbl.getPartitionInfo().idToDataProperty.size());
+ Assert.assertNotEquals(p20211007Id,
tbl.getPartition("p20211007").getId());
+ Assert.assertEquals(p20211006Id,
tbl.getPartition("p20211006").getId());
+ Assert.assertNotNull(tbl.getPartition("p20211006"));
+ Assert.assertNotNull(tbl.getPartition("P20211006"));
+ }
+
@Test
public void testTruncateTable() throws Exception {
String stmtStr = "ALTER TABLE test.tbl ADD PARTITION p20210902 VALUES
[('2021-09-02'), ('2021-09-03')) DISTRIBUTED BY HASH(`k1`) BUCKETS 3;";
diff --git a/fe/fe-core/src/test/resources/help-resource.zip
b/fe/fe-core/src/test/resources/help-resource.zip
new file mode 100644
index 0000000000..7ab08e7bf2
Binary files /dev/null and b/fe/fe-core/src/test/resources/help-resource.zip
differ
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]