Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.iml
*.swp
*.jar
*.zip
*.gz
*.log
*.so.tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6814,7 +6814,7 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti
// 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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1286,11 +1286,13 @@ public OlapTable selectiveCopy(Collection<String> reservedPartitions, IndexExtSt
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum CaseSensibility {
DATABASE(true),
TABLE(true),
ROLLUP(true),
PARTITION(true),
PARTITION(false),
COLUMN(false),
USER(true),
ROLE(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;";
Expand Down
Binary file added fe/fe-core/src/test/resources/help-resource.zip
Binary file not shown.