dengzhhu653 commented on code in PR #5910: URL: https://github.com/apache/hive/pull/5910#discussion_r2176158078
########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java: ########## @@ -4319,19 +4320,30 @@ private List<Partition> add_partitions_core(final RawStore ms, String catName, // incorrect, an exception will be thrown before the threads which create the partition // folders are submitted. This way we can be sure that no partition and no partition // folder will be created if the list contains an invalid partition. - if (validatePartition(part, catName, tblName, dbName, partsToAdd, ms, ifNotExists, - partitionKeys)) { - partitionsToAdd.add(part); - } else { - existingParts.add(part); - } + validatePartition(part, catName, tblName, dbName, partsToAdd); + nameToPart.put(Warehouse.makePartName(partitionKeys, part.getValues()), part); } - // Only authorize on newly created partitions - if (!partitionsToAdd.isEmpty()) { - firePreEvent(new PreAddPartitionEvent(tbl, partitionsToAdd, this)); + List<Partition> existedParts = + ms.getPartitionsByNames(catName, dbName, tblName, + new GetPartitionsArgs.GetPartitionsArgsBuilder().partNames(new ArrayList<>(nameToPart.keySet())).build()); + List<String> existedPartNames = new ArrayList<>(); + for (Partition part : existedParts) { + String partName = Warehouse.makePartName(partitionKeys, part.getValues()); + existedPartNames.add(partName); + existingParts.add(nameToPart.remove(partName)); + } + if (!request.isIfNotExists() && !existedPartNames.isEmpty()) { + throw new AlreadyExistsException("Partition(s) already exist, partition name(s): " + existedPartNames); } + List<Partition> partitionsToAdd = new ArrayList<>(nameToPart.values()); + if (partitionsToAdd.isEmpty()) { Review Comment: Now the `nameToPart` filters all existing partitions, it contains the partitions to be added. We should always have the list of partition names when calling `getPartitionsByNames` -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org