Search in sources :

Example 21 with HiveBasicStatistics

use of io.trino.plugin.hive.HiveBasicStatistics in project trino by trinodb.

the class AlluxioHiveMetastore method getPartitionStatistics.

@Override
public Map<String, PartitionStatistics> getPartitionStatistics(Table table, List<Partition> partitions) {
    try {
        List<String> dataColumns = table.getDataColumns().stream().map(Column::getName).collect(toImmutableList());
        List<String> partitionColumns = table.getPartitionColumns().stream().map(Column::getName).collect(toImmutableList());
        Map<String, HiveBasicStatistics> partitionBasicStatistics = partitions.stream().collect(toImmutableMap(partition -> makePartName(partitionColumns, partition.getValues()), partition -> getHiveBasicStatistics(partition.getParameters())));
        Map<String, OptionalLong> partitionRowCounts = partitionBasicStatistics.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().getRowCount()));
        Map<String, List<ColumnStatisticsInfo>> colStatsMap = client.getPartitionColumnStatistics(table.getDatabaseName(), table.getTableName(), partitionBasicStatistics.keySet().stream().collect(toImmutableList()), dataColumns);
        Map<String, Map<String, HiveColumnStatistics>> partitionColumnStatistics = colStatsMap.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).collect(toImmutableMap(Map.Entry::getKey, entry -> groupStatisticsByColumn(entry.getValue(), partitionRowCounts.getOrDefault(entry.getKey(), OptionalLong.empty()))));
        ImmutableMap.Builder<String, PartitionStatistics> result = ImmutableMap.builder();
        for (String partitionName : partitionBasicStatistics.keySet()) {
            HiveBasicStatistics basicStatistics = partitionBasicStatistics.get(partitionName);
            Map<String, HiveColumnStatistics> columnStatistics = partitionColumnStatistics.getOrDefault(partitionName, ImmutableMap.of());
            result.put(partitionName, new PartitionStatistics(basicStatistics, columnStatistics));
        }
        return result.buildOrThrow();
    } catch (Exception e) {
        throw new TrinoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : ColumnStatisticsInfo(alluxio.grpc.table.ColumnStatisticsInfo) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) Type(io.trino.spi.type.Type) Database(io.trino.plugin.hive.metastore.Database) Function(java.util.function.Function) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) ArrayList(java.util.ArrayList) HiveType(io.trino.plugin.hive.HiveType) OptionalLong(java.util.OptionalLong) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) ThriftMetastoreUtil(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) Column(io.trino.plugin.hive.metastore.Column) HIVE_METASTORE_ERROR(io.trino.plugin.hive.HiveErrorCode.HIVE_METASTORE_ERROR) TableMasterClient(alluxio.client.table.TableMasterClient) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Constraint(alluxio.grpc.table.Constraint) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) TableInfo(alluxio.grpc.table.TableInfo) PartitionWithStatistics(io.trino.plugin.hive.metastore.PartitionWithStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) AcidTransaction(io.trino.plugin.hive.acid.AcidTransaction) Table(io.trino.plugin.hive.metastore.Table) ImmutableMap(com.google.common.collect.ImmutableMap) FileUtils.makePartName(org.apache.hadoop.hive.common.FileUtils.makePartName) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) TupleDomain(io.trino.spi.predicate.TupleDomain) NotFoundException(alluxio.exception.status.NotFoundException) Collectors(java.util.stream.Collectors) RoleGrant(io.trino.spi.security.RoleGrant) PartitionInfo(alluxio.grpc.table.layout.hive.PartitionInfo) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Optional(java.util.Optional) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) Collections(java.util.Collections) HivePrivilege(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege) Partition(io.trino.plugin.hive.metastore.Partition) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) TrinoException(io.trino.spi.TrinoException) NotFoundException(alluxio.exception.status.NotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) OptionalLong(java.util.OptionalLong) TrinoException(io.trino.spi.TrinoException) ArrayList(java.util.ArrayList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 22 with HiveBasicStatistics

use of io.trino.plugin.hive.HiveBasicStatistics in project trino by trinodb.

the class AlluxioHiveMetastore method getTableStatistics.

@Override
public PartitionStatistics getTableStatistics(Table table) {
    try {
        HiveBasicStatistics basicStats = ThriftMetastoreUtil.getHiveBasicStatistics(table.getParameters());
        List<Column> columns = new ArrayList<>(table.getPartitionColumns());
        columns.addAll(table.getDataColumns());
        List<String> columnNames = columns.stream().map(Column::getName).collect(Collectors.toList());
        List<ColumnStatisticsInfo> colStatsList = client.getTableColumnStatistics(table.getDatabaseName(), table.getTableName(), columnNames);
        return new PartitionStatistics(basicStats, groupStatisticsByColumn(colStatsList, basicStats.getRowCount()));
    } catch (Exception e) {
        throw new TrinoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : Column(io.trino.plugin.hive.metastore.Column) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) ArrayList(java.util.ArrayList) ColumnStatisticsInfo(alluxio.grpc.table.ColumnStatisticsInfo) TrinoException(io.trino.spi.TrinoException) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) TrinoException(io.trino.spi.TrinoException) NotFoundException(alluxio.exception.status.NotFoundException)

Aggregations

HiveBasicStatistics (io.trino.plugin.hive.HiveBasicStatistics)22 PartitionStatistics (io.trino.plugin.hive.PartitionStatistics)13 ThriftMetastoreUtil.getHiveBasicStatistics (io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics)13 HiveColumnStatistics (io.trino.plugin.hive.metastore.HiveColumnStatistics)11 TrinoException (io.trino.spi.TrinoException)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)9 Column (io.trino.plugin.hive.metastore.Column)8 List (java.util.List)8 Map (java.util.Map)8 ImmutableList (com.google.common.collect.ImmutableList)7 OptionalLong (java.util.OptionalLong)7 HIVE_METASTORE_ERROR (io.trino.plugin.hive.HiveErrorCode.HIVE_METASTORE_ERROR)6 ColumnStatisticType (io.trino.spi.statistics.ColumnStatisticType)6 Type (io.trino.spi.type.Type)6 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 Set (java.util.Set)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 Sets.difference (com.google.common.collect.Sets.difference)5