use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.
the class TestAddPartitionsFromPartSpec method testAddPartitionSpecBothTypeSet.
@Test
public void testAddPartitionSpecBothTypeSet() throws Exception {
Table table = createTable();
Partition partition = buildPartition(Lists.newArrayList("2013"), getYearPartCol(), 1);
PartitionWithoutSD partitionWithoutSD = buildPartitionWithoutSD(Lists.newArrayList("2014"), 0);
PartitionSpec partitionSpec = new PartitionSpec();
partitionSpec.setDbName(DB_NAME);
partitionSpec.setTableName(TABLE_NAME);
PartitionListComposingSpec partitionListComposingSpec = new PartitionListComposingSpec();
partitionListComposingSpec.setPartitions(Lists.newArrayList(partition));
partitionSpec.setPartitionList(partitionListComposingSpec);
PartitionSpecWithSharedSD partitionSpecWithSharedSD = new PartitionSpecWithSharedSD();
partitionSpecWithSharedSD.setPartitions(Lists.newArrayList(partitionWithoutSD));
partitionSpecWithSharedSD.setSd(buildSD(table.getSd().getLocation() + "/sharedSDTest/"));
partitionSpec.setSharedSDPartitionSpec(partitionSpecWithSharedSD);
PartitionSpecProxy partitionSpecProxy = PartitionSpecProxy.Factory.get(partitionSpec);
client.add_partitions_pspec(partitionSpecProxy);
List<String> partitionNames = client.listPartitionNames(DB_NAME, TABLE_NAME, MAX);
Assert.assertNotNull(partitionNames);
Assert.assertTrue(partitionNames.size() == 1);
Assert.assertEquals("year=2013", partitionNames.get(0));
}
use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.
the class TestAddPartitionsFromPartSpec method testAddPartitionSpecUnsupportedPartSpecType.
@Test
public void testAddPartitionSpecUnsupportedPartSpecType() throws Exception {
createTable();
PartitionSpec partitionSpec = new PartitionSpec();
partitionSpec.setDbName(DB_NAME);
partitionSpec.setTableName(TABLE_NAME);
partitionSpec.setPartitionList(null);
partitionSpec.setSharedSDPartitionSpec(null);
try {
PartitionSpecProxy bubu = PartitionSpecProxy.Factory.get(partitionSpec);
client.add_partitions_pspec(bubu);
Assert.fail("AssertionError should have been thrown.");
} catch (AssertionError e) {
// Expected error
}
}
use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.
the class TestAddPartitionsFromPartSpec method buildPartitionSpec.
private PartitionSpecProxy buildPartitionSpec(String dbName, String tableName, String rootPath, List<Partition> partitions) throws MetaException {
PartitionSpec partitionSpec = new PartitionSpec();
partitionSpec.setDbName(dbName);
partitionSpec.setRootPath(rootPath);
partitionSpec.setTableName(tableName);
PartitionListComposingSpec partitionListComposingSpec = new PartitionListComposingSpec();
partitionListComposingSpec.setPartitions(partitions);
partitionSpec.setPartitionList(partitionListComposingSpec);
return PartitionSpecProxy.Factory.get(partitionSpec);
}
use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.
the class TestAddPartitionsFromPartSpec method buildPartitionSpecWithSharedSD.
private PartitionSpecProxy buildPartitionSpecWithSharedSD(List<PartitionWithoutSD> partitions, StorageDescriptor sd) throws MetaException {
PartitionSpec partitionSpec = new PartitionSpec();
partitionSpec.setDbName(DB_NAME);
partitionSpec.setTableName(TABLE_NAME);
PartitionSpecWithSharedSD partitionList = new PartitionSpecWithSharedSD();
partitionList.setPartitions(partitions);
partitionList.setSd(sd);
partitionSpec.setSharedSDPartitionSpec(partitionList);
return PartitionSpecProxy.Factory.get(partitionSpec);
}
use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.
the class TestMetaStoreServerUtils method testGetPartitionspecsGroupedBySDonePartitionExternal.
/**
* Test getPartitionspecsGroupedByStorageDescriptor() for partitions with a single
* partition which is located outside table location.
*/
@Test
public void testGetPartitionspecsGroupedBySDonePartitionExternal() throws MetaException {
// Create database and table
Table tbl = new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME).addCol("id", "int").setLocation("/foo").build(null);
Partition p1 = new PartitionBuilder().setDbName("DB_NAME").setTableName(TABLE_NAME).setLocation("/a/b").addCol("a", "int").addValue("val1").setInputFormat("foo").build(null);
List<PartitionSpec> result = MetaStoreServerUtils.getPartitionspecsGroupedByStorageDescriptor(tbl, Collections.singleton(p1));
assertThat(result.size(), is(1));
PartitionSpec ps = result.get(0);
assertThat(ps.getRootPath(), is((String) null));
List<Partition> partitions = ps.getPartitionList().getPartitions();
assertThat(partitions.size(), is(1));
Partition partition = partitions.get(0);
assertThat(partition.getSd().getLocation(), is("/a/b"));
assertThat(partition.getValues(), is(Collections.singletonList("val1")));
}
Aggregations