use of com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR in project presto by prestodb.
the class ThriftHiveMetastore method updatePartitionStatistics.
@Override
public synchronized void updatePartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
PartitionStatistics currentStatistics = requireNonNull(getPartitionStatistics(metastoreContext, databaseName, tableName, ImmutableSet.of(partitionName)).get(partitionName), "getPartitionStatistics() returned null");
PartitionStatistics updatedStatistics = update.apply(currentStatistics);
List<Partition> partitions = getPartitionsByNames(metastoreContext, databaseName, tableName, ImmutableList.of(partitionName));
if (partitions.size() != 1) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Metastore returned multiple partitions for name: " + partitionName);
}
Partition originalPartition = getOnlyElement(partitions);
Partition modifiedPartition = originalPartition.deepCopy();
HiveBasicStatistics basicStatistics = updatedStatistics.getBasicStatistics();
modifiedPartition.setParameters(updateStatisticsParameters(modifiedPartition.getParameters(), basicStatistics));
alterPartitionWithoutStatistics(metastoreContext, databaseName, tableName, modifiedPartition);
Map<String, HiveType> columns = modifiedPartition.getSd().getCols().stream().collect(toImmutableMap(FieldSchema::getName, schema -> metastoreContext.getColumnConverter().toColumn(schema).getType()));
setPartitionColumnStatistics(metastoreContext, databaseName, tableName, partitionName, columns, updatedStatistics.getColumnStatistics(), basicStatistics.getRowCount());
Set<String> removedStatistics = difference(currentStatistics.getColumnStatistics().keySet(), updatedStatistics.getColumnStatistics().keySet());
removedStatistics.forEach(column -> deletePartitionColumnStatistics(metastoreContext, databaseName, tableName, partitionName, column));
}
use of com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR 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.HiveErrorCode.HIVE_METASTORE_ERROR 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