use of org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy in project hive by apache.
the class TestAddPartitionsFromPartSpec method testAddPartitionSpec.
// Tests for int add_partitions_pspec(PartitionSpecProxy partitionSpec) method
@Test
public void testAddPartitionSpec() throws Exception {
Table table = createTable();
Partition partition1 = buildPartition(Lists.newArrayList("2013"), getYearPartCol(), 1);
Partition partition2 = buildPartition(Lists.newArrayList("2014"), getYearPartCol(), 2);
Partition partition3 = buildPartition(Lists.newArrayList("2012"), getYearPartCol(), 3);
List<Partition> partitions = Lists.newArrayList(partition1, partition2, partition3);
String rootPath = table.getSd().getLocation() + "/addpartspectest/";
PartitionSpecProxy partitionSpec = buildPartitionSpec(DB_NAME, TABLE_NAME, rootPath, partitions);
client.add_partitions_pspec(partitionSpec);
verifyPartition(table, "year=2013", Lists.newArrayList("2013"), 1);
verifyPartition(table, "year=2014", Lists.newArrayList("2014"), 2);
verifyPartition(table, "year=2012", Lists.newArrayList("2012"), 3);
}
use of org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy in project hive by apache.
the class TestAddPartitionsFromPartSpec method testAddPartitionSpecPartDuplicateInSpec.
@Test
public void testAddPartitionSpecPartDuplicateInSpec() throws Exception {
createTable();
List<Partition> partitions = buildPartitions(DB_NAME, TABLE_NAME, Lists.newArrayList("2014", "2015", "2017", "2017", "2018", "2019"));
PartitionSpecProxy partitionSpecProxy = buildPartitionSpec(DB_NAME, TABLE_NAME, null, partitions);
try {
client.add_partitions_pspec(partitionSpecProxy);
Assert.fail("MetaException should have happened.");
} catch (MetaException e) {
// Expected exception
}
List<Partition> parts = client.listPartitions(DB_NAME, TABLE_NAME, MAX);
Assert.assertNotNull(parts);
Assert.assertTrue(parts.isEmpty());
for (Partition partition : partitions) {
Assert.assertFalse(metaStore.isPathExists(new Path(partition.getSd().getLocation())));
}
}
use of org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy in project hive by apache.
the class TestAddPartitionsFromPartSpec method testAddPartitionSpecWithSharedSDNullLocation.
@Test(expected = MetaException.class)
public void testAddPartitionSpecWithSharedSDNullLocation() throws Exception {
createTable();
PartitionWithoutSD partition = buildPartitionWithoutSD(Lists.newArrayList("2002"), 0);
partition.setRelativePath("year2002");
String location = null;
PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), buildSD(location));
client.add_partitions_pspec(partitionSpecProxy);
}
use of org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy in project hive by apache.
the class TestAddPartitionsFromPartSpec method testAddPartitionSpecDBAndTableSetFromSpecProxy.
@Test
public void testAddPartitionSpecDBAndTableSetFromSpecProxy() throws Exception {
createTable();
Partition partition = buildPartition(DB_NAME, TABLE_NAME, DEFAULT_YEAR_VALUE);
partition.setDbName(null);
partition.setTableName(null);
PartitionSpecProxy partitionSpecProxy = buildPartitionSpec(null, null, null, Lists.newArrayList(partition));
partitionSpecProxy.setDbName(DB_NAME);
partitionSpecProxy.setTableName(TABLE_NAME);
client.add_partitions_pspec(partitionSpecProxy);
Partition resultPart = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList(DEFAULT_YEAR_VALUE));
Assert.assertNotNull(resultPart);
}
use of org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy in project hive by apache.
the class CachedStore method addPartitions.
@Override
public boolean addPartitions(String dbName, String tblName, PartitionSpecProxy partitionSpec, boolean ifNotExists) throws InvalidObjectException, MetaException {
boolean succ = rawStore.addPartitions(dbName, tblName, partitionSpec, ifNotExists);
if (succ) {
dbName = StringUtils.normalizeIdentifier(dbName);
tblName = StringUtils.normalizeIdentifier(tblName);
if (!shouldCacheTable(dbName, tblName)) {
return succ;
}
PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator();
while (iterator.hasNext()) {
Partition part = iterator.next();
sharedCache.addPartitionToCache(dbName, tblName, part);
}
}
return succ;
}
Aggregations