wecharyu commented on code in PR #4123:
URL: https://github.com/apache/hive/pull/4123#discussion_r1162961355
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestObjectStore.java:
##########
@@ -498,6 +497,68 @@ public void testPartitionOpsWhenTableDoesNotExist() throws
InvalidObjectExceptio
}
}
+ @Test
+ public void testDropPartitionByName() throws Exception {
+ Database db1 = new DatabaseBuilder()
+ .setName(DB1)
+ .setDescription("description")
+ .setLocation("locationurl")
+ .build(conf);
+ try (AutoCloseable c = deadline()) {
+ objectStore.createDatabase(db1);
+ }
+ StorageDescriptor sd = createFakeSd("location");
+ HashMap<String, String> tableParams = new HashMap<>();
+ tableParams.put("EXTERNAL", "false");
+ FieldSchema partitionKey1 = new FieldSchema("Country",
ColumnType.STRING_TYPE_NAME, "");
+ FieldSchema partitionKey2 = new FieldSchema("State",
ColumnType.STRING_TYPE_NAME, "");
+ Table tbl1 =
+ new Table(TABLE1, DB1, "owner", 1, 2, 3, sd,
Arrays.asList(partitionKey1, partitionKey2),
+ tableParams, null, null, "MANAGED_TABLE");
+ try (AutoCloseable c = deadline()) {
+ objectStore.createTable(tbl1);
+ }
+ HashMap<String, String> partitionParams = new HashMap<>();
+ partitionParams.put("PARTITION_LEVEL_PRIVILEGE", "true");
+ List<String> value1 = Arrays.asList("US", "CA");
+ Partition part1 = new Partition(value1, DB1, TABLE1, 111, 111, sd,
partitionParams);
+ part1.setCatName(DEFAULT_CATALOG_NAME);
+ try (AutoCloseable c = deadline()) {
+ objectStore.addPartition(part1);
+ }
+ List<String> value2 = Arrays.asList("US", "MA");
+ Partition part2 = new Partition(value2, DB1, TABLE1, 222, 222, sd,
partitionParams);
+ part2.setCatName(DEFAULT_CATALOG_NAME);
+ try (AutoCloseable c = deadline()) {
+ objectStore.addPartition(part2);
+ }
+
+ List<Partition> partitions;
+ try (AutoCloseable c = deadline()) {
+ objectStore.dropPartition(DEFAULT_CATALOG_NAME, DB1, TABLE1,
"country=US/state=CA");
+ partitions = objectStore.getPartitions(DEFAULT_CATALOG_NAME, DB1,
TABLE1, 10);
+ }
+ Assert.assertEquals(1, partitions.size());
+ Assert.assertEquals(222, partitions.get(0).getCreateTime());
+ try (AutoCloseable c = deadline()) {
+ objectStore.dropPartition(DEFAULT_CATALOG_NAME, DB1, TABLE1,
"country=US/state=MA");
+ partitions = objectStore.getPartitions(DEFAULT_CATALOG_NAME, DB1,
TABLE1, 10);
+ }
+ Assert.assertEquals(0, partitions.size());
+
+ try (AutoCloseable c = deadline()) {
+ // Illegal partName will do nothing, it doesn't matter
+ // because the real HMSHandler will guarantee the partName is legal and
exists.
+ objectStore.dropPartition(DEFAULT_CATALOG_NAME, DB1, TABLE1,
"country=US/state=NON_EXIST");
+ objectStore.dropPartition(DEFAULT_CATALOG_NAME, DB1, TABLE1,
"country=US/st=CA");
Review Comment:
It will not return false for non-existent partition, `HMSHandler` has
already checked the existence of the partition and it does not need a double
check in `ObjectStore`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]