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 662de9a..110e082 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 @@ -3376,12 +3376,25 @@ public Partition exchange_partition(Map partitionSpecs, public List exchange_partitions(Map partitionSpecs, String sourceDbName, String sourceTableName, String destDbName, String destTableName) throws TException { + if (partitionSpecs == null || sourceDbName == null || sourceTableName == null + || destDbName == null || destTableName == null) { + throw new MetaException("The DB and table name for the source and destination tables," + + " and the partition specs must not be null."); + } boolean success = false; boolean pathCreated = false; RawStore ms = getMS(); ms.openTransaction(); Table destinationTable = ms.getTable(destDbName, destTableName); + if (destinationTable == null) { + throw new MetaException( + "The destination table " + destDbName + "." + destTableName + " not found"); + } Table sourceTable = ms.getTable(sourceDbName, sourceTableName); + if (sourceTable == null) { + throw new MetaException( + "The source table " + sourceDbName + "." + sourceTableName + " not found"); + } List partVals = MetaStoreUtils.getPvals(sourceTable.getPartitionKeys(), partitionSpecs); List partValsPresent = new ArrayList<> (); 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 5b21491..c9b9e9b 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 @@ -38,7 +38,6 @@ import org.apache.hadoop.hive.metastore.client.builder.TableBuilder; import org.apache.hadoop.hive.metastore.minihms.AbstractMetaStoreService; import org.apache.thrift.TException; -import org.apache.thrift.transport.TTransportException; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -290,160 +289,100 @@ public void testExchangePartitionsNonExistingPartLocation() throws Exception { sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNonExistingSourceTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, DB_NAME, "nonexistingtable", - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, DB_NAME, "nonexistingtable", destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNonExistingSourceDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, "nonexistingdb", sourceTable.getTableName(), - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, "nonexistingdb", sourceTable.getTableName(), + destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNonExistingDestTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), DB_NAME, "nonexistingtable"); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + DB_NAME, "nonexistingtable"); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNonExistingDestDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), "nonexistingdb", destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + "nonexistingdb", destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsEmptySourceTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, DB_NAME, "", destTable.getDbName(), - destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, DB_NAME, "", destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsEmptySourceDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, "", sourceTable.getTableName(), - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, "", sourceTable.getTableName(), + destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsEmptyDestTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), DB_NAME, ""); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + DB_NAME, ""); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsEmptyDestDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), "", destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + "", destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNullSourceTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, DB_NAME, null, destTable.getDbName(), - destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, DB_NAME, null, destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNullSourceDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, null, sourceTable.getTableName(), - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, null, sourceTable.getTableName(), + destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNullDestTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), DB_NAME, null); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + DB_NAME, null); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNullDestDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), null, destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partitions(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + null, destTable.getTableName()); } @Test(expected = MetaException.class) @@ -454,15 +393,10 @@ public void testExchangePartitionsEmptyPartSpec() throws Exception { sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionsNullPartSpec() throws Exception { - try { - client.exchange_partitions(null, sourceTable.getDbName(), sourceTable.getTableName(), null, - destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: NPE should not be thrown - } + client.exchange_partitions(null, sourceTable.getDbName(), sourceTable.getTableName(), null, + destTable.getTableName()); } @Test(expected = MetaException.class) @@ -881,160 +815,100 @@ public void testExchangePartitionNonExistingPartLocation() throws Exception { sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNonExistingSourceTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, DB_NAME, "nonexistingtable", - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, DB_NAME, "nonexistingtable", destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNonExistingSourceDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, "nonexistingdb", sourceTable.getTableName(), - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, "nonexistingdb", sourceTable.getTableName(), + destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNonExistingDestTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), DB_NAME, "nonexistingtable"); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + DB_NAME, "nonexistingtable"); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNonExistingDestDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), "nonexistingdb", destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + "nonexistingdb", destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionEmptySourceTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, DB_NAME, "", destTable.getDbName(), - destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, DB_NAME, "", destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionEmptySourceDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, "", sourceTable.getTableName(), - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, "", sourceTable.getTableName(), destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionEmptyDestTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), DB_NAME, ""); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + DB_NAME, ""); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionEmptyDestDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), "", destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + "", destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNullSourceTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, DB_NAME, null, destTable.getDbName(), - destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, DB_NAME, null, destTable.getDbName(), + destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNullSourceDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, null, sourceTable.getTableName(), - destTable.getDbName(), destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, null, sourceTable.getTableName(), + destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNullDestTable() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), DB_NAME, null); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + DB_NAME, null); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNullDestDB() throws Exception { Map partitionSpecs = getPartitionSpec(partitions[1]); - try { - client.exchange_partition(partitionSpecs, sourceTable.getDbName(), - sourceTable.getTableName(), null, destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: Non existing table or db should be handled correctly and NPE should not occur. - } + client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), + null, destTable.getTableName()); } @Test(expected = MetaException.class) @@ -1045,15 +919,11 @@ public void testExchangePartitionEmptyPartSpec() throws Exception { sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); } - @Test + @Test(expected = MetaException.class) public void testExchangePartitionNullPartSpec() throws Exception { - try { - client.exchange_partition(null, sourceTable.getDbName(), sourceTable.getTableName(), null, - destTable.getTableName()); - Assert.fail("Exception should have been thrown."); - } catch (TTransportException | NullPointerException e) { - // TODO: NPE should not be thrown - } + + client.exchange_partition(null, sourceTable.getDbName(), sourceTable.getTableName(), null, + destTable.getTableName()); } @Test(expected = MetaException.class)