diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 47de215..4d76331 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -3347,6 +3347,10 @@ public Partition exchange_partition(Map partitionSpecs, } List partitionsToExchange = get_partitions_ps(sourceDbName, sourceTableName, partVals, (short)-1); + if (partitionsToExchange == null || partitionsToExchange.isEmpty()) { + throw new MetaException("No partition is found with the values " + partitionSpecs + + " for the table " + sourceTableName); + } boolean sameColumns = MetaStoreUtils.compareFieldColumns( sourceTable.getSd().getCols(), destinationTable.getSd().getCols()); boolean samePartitions = MetaStoreUtils.compareFieldColumns( diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestExchangePartitions.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestExchangePartitions.java index 3a06aec..1c2b7a9 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestExchangePartitions.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestExchangePartitions.java @@ -720,8 +720,6 @@ public void testExchangePartitionsYearAndDaySetInPartSpec() throws Exception { @Test(expected = MetaException.class) public void testExchangePartitionsNoPartExists() throws Exception { - // TODO: FileNotFoundException will occur. This use case could be handled in a better way like - // checking if the partitionsToExchange is empty and throw an exception if it is. Map partitionSpecs = getPartitionSpec(Lists.newArrayList("2017", "march", "25")); client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), @@ -1313,8 +1311,6 @@ public void testExchangePartitionYearAndDaySetInPartSpec() throws Exception { @Test(expected = MetaException.class) public void testExchangePartitionNoPartExists() throws Exception { - // TODO: FileNotFoundException will occur. This use case could be handled in a better way like - // checking if the partitionsToExchange is empty and throw an exception if it is. Map partitionSpecs = getPartitionSpec(Lists.newArrayList("2017", "march", "25")); client.exchange_partition(partitionSpecs, sourceTable.getDbName(),