Search in sources :

Example 11 with PartitionSpec

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));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionWithoutSD(org.apache.hadoop.hive.metastore.api.PartitionWithoutSD) PartitionListComposingSpec(org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec) PartitionSpecProxy(org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 12 with PartitionSpec

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
    }
}
Also used : PartitionSpecProxy(org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 13 with PartitionSpec

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);
}
Also used : PartitionListComposingSpec(org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec)

Example 14 with 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);
}
Also used : PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD)

Example 15 with 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")));
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Aggregations

PartitionSpec (org.apache.hadoop.hive.metastore.api.PartitionSpec)27 Test (org.junit.Test)14 Partition (org.apache.hadoop.hive.metastore.api.Partition)13 PartitionWithoutSD (org.apache.hadoop.hive.metastore.api.PartitionWithoutSD)12 ArrayList (java.util.ArrayList)11 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)10 PartitionSpecWithSharedSD (org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD)10 Table (org.apache.hadoop.hive.metastore.api.Table)9 PartitionListComposingSpec (org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec)6 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)6 PartitionsByExprRequest (org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest)5 List (java.util.List)4 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)4 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)4 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)4 PartitionSpecProxy (org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy)4 HashMap (java.util.HashMap)3 GetPartitionsRequest (org.apache.hadoop.hive.metastore.api.GetPartitionsRequest)3 GetPartitionsResponse (org.apache.hadoop.hive.metastore.api.GetPartitionsResponse)3 GetProjectionsSpec (org.apache.hadoop.hive.metastore.api.GetProjectionsSpec)3