public boolean dropPartition(String dbName, String tableName, List<String> partVals, PartitionDropOptions options) throws HiveException { try { return getMSC().dropPartition(dbName, tableName, partVals, options); } catch (NoSuchObjectException e) { throw new HiveException("Partition or table doesn't exist.", e); } catch (Exception e) { throw new HiveException(e.getMessage(), e); } }
@Test(expected = MetaException.class) public void testDropPartitionNullVal() throws Exception { List<String> partVals = new ArrayList<>(); partVals.add(null); partVals.add(null); client.dropPartition(DB_NAME, TABLE_NAME, partVals, false); }
@Test(expected = MetaException.class) public void testDropPartitionNullPartVals() throws Exception { List<String> partVals = null; client.dropPartition(DB_NAME, TABLE_NAME, partVals, false); }
@Test(expected = MetaException.class) public void testDropPartitionByNameNullName() throws Exception { String name = null; client.dropPartition(DB_NAME, TABLE_NAME, name, true); }
@Test(expected = MetaException.class) public void testDropPartitionEmptyPartVals() throws Exception { List<String> partVals = new ArrayList<>(); client.dropPartition(DB_NAME, TABLE_NAME, partVals, false); }
@Test(expected = NoSuchObjectException.class) public void testDropPartitionEmptyVal() throws Exception { List<String> partVals = new ArrayList<>(); partVals.add(""); partVals.add(""); client.dropPartition(DB_NAME, TABLE_NAME, partVals, false); }
@Test(expected = MetaException.class) public void testDropPartitionNullTable() throws Exception { client.dropPartition(DB_NAME, null, Lists.newArrayList("2017"), false); }
@Test(expected = NoSuchObjectException.class) public void testDropPartitionByNameInvalidNameFormat() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, "invalidnameformat", true); }
@Test(expected = MetaException.class) public void testDropPartitionMoreValsInList() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2017", "march", "12:00"), false); }
@Test public void testDropPartitionByNameMoreValue() throws Exception { // The extra non existing values will be ignored. client.dropPartition(DB_NAME, TABLE_NAME, "year=2017/month=march/day=10", true); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); }
@Test public void testDropPartitionByName() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, "year=2017/month=march", false); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, false, false); }
private void dropPartition(Partition partition, boolean ifExists, boolean deleteData) throws HCatException, MetaException, TException { try { hmsClient.dropPartition(partition.getDbName(), partition.getTableName(), partition.getValues(), deleteData); } catch (NoSuchObjectException e) { if (!ifExists) { throw new ObjectNotFoundException( "NoSuchObjectException while dropping partition: " + partition.getValues(), e); } } }
@Test public void testDropPartitionNullPartDropOptions() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), null); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); }
@Test public void testDropPartitionDeleteData() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), true); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); }
@Test public void testDropPartitionDeleteParentDir() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), true); client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[1].getValues(), true); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0], PARTITIONS[1]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); Path parentPath = new Path(PARTITIONS[0].getSd().getLocation()).getParent(); Assert.assertFalse("The parent path '" + parentPath.toString() + "' should not exist.", metaStore.isPathExists(parentPath)); }
@Test public void testDropPartition() throws Exception { boolean dropSuccessful = client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), false); Assert.assertTrue(dropSuccessful); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, false, false); }
@Test public void testDropPartitionNotDeleteData() throws Exception { PartitionDropOptions partDropOptions = PartitionDropOptions.instance(); partDropOptions.deleteData(false); partDropOptions.purgeData(false); client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), partDropOptions); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, false, false); }
@Test public void testDropPartitionNotDeleteDataPurge() throws Exception { PartitionDropOptions partDropOptions = PartitionDropOptions.instance(); partDropOptions.deleteData(false); partDropOptions.purgeData(true); client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), partDropOptions); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, false, false); }
@Test public void testDropPartitionDeleteDataNoPurge() throws Exception { PartitionDropOptions partDropOptions = PartitionDropOptions.instance(); partDropOptions.deleteData(true); partDropOptions.purgeData(false); client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), partDropOptions); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); }
@Test public void testDropPartitionDeleteDataAndPurge() throws Exception { PartitionDropOptions partDropOptions = PartitionDropOptions.instance(); partDropOptions.deleteData(true); partDropOptions.purgeData(true); client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), partDropOptions); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, true); }