[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.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,7 +5,6 @@
|
||||
*.iml
|
||||
*.swp
|
||||
*.jar
|
||||
*.zip
|
||||
*.gz
|
||||
*.log
|
||||
*.so.tmp
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ public enum CaseSensibility {
|
||||
DATABASE(true),
|
||||
TABLE(true),
|
||||
ROLLUP(true),
|
||||
PARTITION(true),
|
||||
PARTITION(false),
|
||||
COLUMN(false),
|
||||
USER(true),
|
||||
ROLE(false),
|
||||
|
||||
@ -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;";
|
||||
|
||||
BIN
fe/fe-core/src/test/resources/help-resource.zip
Normal file
BIN
fe/fe-core/src/test/resources/help-resource.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user