diff --git a/.gitignore b/.gitignore index aed8a347ba08d2..9a42e446d6b162 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 dd89a77a9413e1..d0cab71cad6bed 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 void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti // check partitions for (Map.Entry 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 e108fb82d78057..c7795d5e2745ea 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 OlapTable selectiveCopy(Collection reservedPartitions, IndexExtSt return copied; } - Set partNames = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER); + Set partNames = Sets.newHashSet(); partNames.addAll(copied.getPartitionNames()); + // partition name is case insensitive: + Set 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 ebd7b63b5b46b7..d0545a14dda643 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 db8951da4e8d8b..80aec2011f2826 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 static void setup() throws Exception { "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 static void tearDown() { 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 00000000000000..7ab08e7bf20a74 Binary files /dev/null and b/fe/fe-core/src/test/resources/help-resource.zip differ