use of com.facebook.presto.hive.metastore.Partition in project presto by prestodb.
the class GlueHiveMetastore method getPartitionNamesByFilter.
/**
* <pre>
* Ex: Partition keys = ['a', 'b', 'c']
* Valid partition values:
* ['1','2','3'] or
* ['', '2', '']
* </pre>
*
* @param partitionPredicates Full or partial list of partition values to filter on. Keys without filter will be empty strings.
* @return a list of partition names.
*/
@Override
public List<String> getPartitionNamesByFilter(MetastoreContext metastoreContext, String databaseName, String tableName, Map<Column, Domain> partitionPredicates) {
Table table = getTableOrElseThrow(metastoreContext, databaseName, tableName);
List<String> parts = convertPredicateToParts(partitionPredicates);
String expression = buildGlueExpression(table.getPartitionColumns(), parts);
List<Partition> partitions = getPartitions(databaseName, tableName, expression);
return buildPartitionNames(table.getPartitionColumns(), partitions);
}
use of com.facebook.presto.hive.metastore.Partition in project presto by prestodb.
the class GlueHiveMetastore method getPartitionStatistics.
@Override
public Map<String, PartitionStatistics> getPartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Set<String> partitionNames) {
ImmutableMap.Builder<String, PartitionStatistics> result = ImmutableMap.builder();
getPartitionsByNames(metastoreContext, databaseName, tableName, ImmutableList.copyOf(partitionNames)).forEach((partitionName, optionalPartition) -> {
Partition partition = optionalPartition.orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), toPartitionValues(partitionName)));
PartitionStatistics partitionStatistics = new PartitionStatistics(getHiveBasicStatistics(partition.getParameters()), ImmutableMap.of());
result.put(partitionName, partitionStatistics);
});
return result.build();
}
use of com.facebook.presto.hive.metastore.Partition in project presto by prestodb.
the class BridgingHiveMetastore method getPartitionsByNames.
@Override
public Map<String, Optional<Partition>> getPartitionsByNames(MetastoreContext metastoreContext, String databaseName, String tableName, List<String> partitionNames) {
requireNonNull(partitionNames, "partitionNames is null");
if (partitionNames.isEmpty()) {
return ImmutableMap.of();
}
Map<String, List<String>> partitionNameToPartitionValuesMap = partitionNames.stream().collect(Collectors.toMap(identity(), MetastoreUtil::toPartitionValues));
Map<List<String>, Partition> partitionValuesToPartitionMap = delegate.getPartitionsByNames(metastoreContext, databaseName, tableName, partitionNames).stream().map(partition -> fromMetastoreApiPartition(partition, partitionMutator, metastoreContext.getColumnConverter())).collect(Collectors.toMap(Partition::getValues, identity()));
ImmutableMap.Builder<String, Optional<Partition>> resultBuilder = ImmutableMap.builder();
for (Map.Entry<String, List<String>> entry : partitionNameToPartitionValuesMap.entrySet()) {
Partition partition = partitionValuesToPartitionMap.get(entry.getValue());
resultBuilder.put(entry.getKey(), Optional.ofNullable(partition));
}
return resultBuilder.build();
}
use of com.facebook.presto.hive.metastore.Partition in project presto by prestodb.
the class AlluxioHiveMetastore method getPartitionNamesByParts.
/**
* return a list of partition names by which the values of each partition is at least
* contained which the {@code parts} argument
*
* @param databaseName database name
* @param tableName table name
* @param parts list of values which returned partitions should contain
* @return optionally, a list of strings where each entry is in the form of {key}={value}
*/
public Optional<List<String>> getPartitionNamesByParts(MetastoreContext metastoreContext, String databaseName, String tableName, List<String> parts) {
try {
List<PartitionInfo> partitionInfos = AlluxioProtoUtils.toPartitionInfoList(client.readTable(databaseName, tableName, Constraint.getDefaultInstance()));
// TODO also check for database name equality
partitionInfos = partitionInfos.stream().filter(p -> p.getTableName().equals(tableName)).filter(partition -> {
List<String> values = partition.getValuesList();
if (values.size() != parts.size()) {
return false;
}
for (int i = 0; i < values.size(); i++) {
String constraintPart = parts.get(i);
if (!constraintPart.isEmpty() && !values.get(i).equals(constraintPart)) {
return false;
}
}
return true;
}).collect(toImmutableList());
List<String> partitionNames = partitionInfos.stream().map(PartitionInfo::getPartitionName).collect(toImmutableList());
return Optional.of(partitionNames);
} catch (AlluxioStatusException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.hive.metastore.Partition in project presto by prestodb.
the class AlluxioHiveMetastore method getPartitionsByNames.
@Override
public Map<String, Optional<Partition>> getPartitionsByNames(MetastoreContext metastoreContext, String databaseName, String tableName, List<String> partitionNames) {
if (partitionNames.isEmpty()) {
return ImmutableMap.of();
}
try {
// Get all partitions
List<PartitionInfo> partitionInfos = AlluxioProtoUtils.toPartitionInfoList(client.readTable(databaseName, tableName, Constraint.getDefaultInstance()));
// TODO also check for database name equality
partitionInfos = partitionInfos.stream().filter(p -> p.getTableName().equals(tableName)).collect(toImmutableList());
return partitionInfos.stream().filter(p -> partitionNames.stream().anyMatch(p.getPartitionName()::equals)).collect(toImmutableMap(PartitionInfo::getPartitionName, partitionInfo -> Optional.of(AlluxioProtoUtils.fromProto(partitionInfo))));
} catch (AlluxioStatusException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
Aggregations