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;
}
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());
}
}
Aggregations