Search in sources :

Example 26 with PartitionSpec

use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.

the class MetaStoreServerUtils method getSharedSDPartSpec.

/**
 * Convert list of partitions to a PartitionSpec object.
 */
private static PartitionSpec getSharedSDPartSpec(Table table, StorageDescriptorKey sdKey, List<PartitionWithoutSD> partitions) {
    StorageDescriptor sd;
    if (sdKey.getSd() == null) {
        // sd is not requested set it empty StorageDescriptor in the PartitionSpec
        sd = new StorageDescriptor();
    } else {
        sd = new StorageDescriptor(sdKey.getSd());
        // Use table-dir as root-dir.
        sd.setLocation(sdKey.baseLocation);
    }
    PartitionSpecWithSharedSD sharedSDPartSpec = new PartitionSpecWithSharedSD();
    sharedSDPartSpec.setPartitions(partitions);
    sharedSDPartSpec.setSd(sd);
    PartitionSpec ret = new PartitionSpec();
    ret.setRootPath(sd.getLocation());
    ret.setSharedSDPartitionSpec(sharedSDPartSpec);
    ret.setDbName(table.getDbName());
    ret.setTableName(table.getTableName());
    ret.setCatName(table.getCatName());
    return ret;
}
Also used : StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) PartitionSpecWithSharedSD(org.apache.hadoop.hive.metastore.api.PartitionSpecWithSharedSD) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec)

Example 27 with PartitionSpec

use of org.apache.hadoop.hive.metastore.api.PartitionSpec in project hive by apache.

the class TestGetPartitionsUsingProjectionAndFilterSpecs method testPartitionProjectionEmptySpec.

@Test
public void testPartitionProjectionEmptySpec() throws Throwable {
    GetPartitionsRequest request = getGetPartitionsRequest();
    GetProjectionsSpec projectSpec = request.getProjectionSpec();
    projectSpec.setFieldList(new ArrayList<>(0));
    projectSpec.setExcludeParamKeyPattern("exclude%");
    GetPartitionsResponse response;
    response = client.getPartitionsWithSpecs(request);
    Assert.assertEquals(1, response.getPartitionSpec().size());
    PartitionSpec partitionSpec = response.getPartitionSpec().get(0);
    PartitionSpecWithSharedSD partitionSpecWithSharedSD = partitionSpec.getSharedSDPartitionSpec();
    StorageDescriptor sharedSD = partitionSpecWithSharedSD.getSd();
    Assert.assertNotNull(sharedSD);
    // everything except location in sharedSD should be same
    StorageDescriptor origSd = origPartitions.get(0).getSd().deepCopy();
    origSd.unsetLocation();
    StorageDescriptor sharedSDCopy = sharedSD.deepCopy();
    sharedSDCopy.unsetLocation();
    Assert.assertEquals(origSd, sharedSDCopy);
    List<PartitionWithoutSD> partitionWithoutSDS = partitionSpecWithSharedSD.getPartitions();
    Assert.assertNotNull(partitionWithoutSDS);
    Assert.assertEquals("Unexpected number of partitions returned", origPartitions.size(), partitionWithoutSDS.size());
    for (int i = 0; i < origPartitions.size(); i++) {
        Partition origPartition = origPartitions.get(i);
        PartitionWithoutSD retPartition = partitionWithoutSDS.get(i);
        Assert.assertEquals(origPartition.getCreateTime(), retPartition.getCreateTime());
        Assert.assertEquals(origPartition.getLastAccessTime(), retPartition.getLastAccessTime());
        Assert.assertEquals(origPartition.getSd().getLocation(), sharedSD.getLocation() + retPartition.getRelativePath());
        validateMap(origPartition.getParameters(), retPartition.getParameters());
        validateList(origPartition.getValues(), retPartition.getValues());
    }
}
Also used : GetProjectionsSpec(org.apache.hadoop.hive.metastore.api.GetProjectionsSpec) Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionWithoutSD(org.apache.hadoop.hive.metastore.api.PartitionWithoutSD) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) GetPartitionsResponse(org.apache.hadoop.hive.metastore.api.GetPartitionsResponse) GetPartitionsRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsRequest) 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)

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