Search in sources :

Example 6 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

the class HiveMetadata method createPartitionStatistics.

private PartitionStatistics createPartitionStatistics(ConnectorSession session, Map<String, Type> columnTypes, ComputedStatistics computedStatistics) {
    Map<ColumnStatisticMetadata, Block> computedColumnStatistics = computedStatistics.getColumnStatistics();
    Block rowCountBlock = Optional.ofNullable(computedStatistics.getTableStatistics().get(ROW_COUNT)).orElseThrow(() -> new VerifyException("rowCount not present"));
    verify(!rowCountBlock.isNull(0), "rowCount must never be null");
    long rowCount = BIGINT.getLong(rowCountBlock, 0);
    HiveBasicStatistics rowCountOnlyBasicStatistics = new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.of(rowCount), OptionalLong.empty(), OptionalLong.empty());
    return createPartitionStatistics(session, rowCountOnlyBasicStatistics, columnTypes, computedColumnStatistics);
}
Also used : ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) VerifyException(com.google.common.base.VerifyException) Block(io.prestosql.spi.block.Block)

Example 7 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

the class TestStatisticAggregationsDescriptor method createTestDescriptor.

private static StatisticAggregationsDescriptor<Symbol> createTestDescriptor() {
    StatisticAggregationsDescriptor.Builder<Symbol> builder = StatisticAggregationsDescriptor.builder();
    PlanSymbolAllocator planSymbolAllocator = new PlanSymbolAllocator();
    for (String column : COLUMNS) {
        for (ColumnStatisticType type : ColumnStatisticType.values()) {
            builder.addColumnStatistic(new ColumnStatisticMetadata(column, type), testSymbol(planSymbolAllocator));
        }
        builder.addGrouping(column, testSymbol(planSymbolAllocator));
    }
    builder.addTableStatistic(ROW_COUNT, testSymbol(planSymbolAllocator));
    return builder.build();
}
Also used : ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) Symbol(io.prestosql.spi.plan.Symbol) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator)

Example 8 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

the class StatisticsUtils method fromComputedStatistics.

public static TableStatisticsData fromComputedStatistics(ConnectorSession session, Collection<ComputedStatistics> computedStatistics, long rowCount, Map<String, ColumnHandle> columnHandles, TypeManager typeManager) {
    TableStatisticsData.Builder tableStatBuilder = TableStatisticsData.builder();
    tableStatBuilder.setRowCount(rowCount);
    // organize the column stats into a per-column view
    Map<String, Map<ColumnStatisticType, Block>> perColumnStats = new HashMap<>();
    for (ComputedStatistics stat : computedStatistics) {
        for (Map.Entry<ColumnStatisticMetadata, Block> entry : stat.getColumnStatistics().entrySet()) {
            perColumnStats.putIfAbsent(entry.getKey().getColumnName(), new HashMap<>());
            perColumnStats.get(entry.getKey().getColumnName()).put(entry.getKey().getStatisticType(), entry.getValue());
        }
    }
    // build the per-column statistics
    for (Map.Entry<String, ColumnHandle> entry : columnHandles.entrySet()) {
        Map<ColumnStatisticType, Block> columnStat = perColumnStats.get(entry.getKey());
        if (columnStat == null) {
            continue;
        }
        MemoryColumnHandle handle = (MemoryColumnHandle) entry.getValue();
        Type columnType = handle.getType(typeManager);
        tableStatBuilder.setColumnStatistics(handle.getColumnName(), fromComputedStatistics(session, columnStat, rowCount, columnType));
    }
    return tableStatBuilder.build();
}
Also used : ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) MemoryColumnHandle(io.prestosql.plugin.memory.MemoryColumnHandle) HashMap(java.util.HashMap) MemoryColumnHandle(io.prestosql.plugin.memory.MemoryColumnHandle) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) DecimalType(io.prestosql.spi.type.DecimalType) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) MapType(io.prestosql.spi.type.MapType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) ArrayType(io.prestosql.spi.type.ArrayType) ComputedStatistics(io.prestosql.spi.statistics.ComputedStatistics) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) Block(io.prestosql.spi.block.Block) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ColumnStatisticMetadata (io.prestosql.spi.statistics.ColumnStatisticMetadata)8 Block (io.prestosql.spi.block.Block)5 ColumnStatisticType (io.prestosql.spi.statistics.ColumnStatisticType)4 Type (io.prestosql.spi.type.Type)4 StatisticAggregationsDescriptor (io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor)3 Test (org.testng.annotations.Test)3 VerifyException (com.google.common.base.VerifyException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Session (io.prestosql.Session)2 TableFinishOperatorFactory (io.prestosql.operator.TableFinishOperator.TableFinishOperatorFactory)2 LongArrayBlockBuilder (io.prestosql.spi.block.LongArrayBlockBuilder)2 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)2 Symbol (io.prestosql.spi.plan.Symbol)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MemoryColumnHandle (io.prestosql.plugin.memory.MemoryColumnHandle)1 PrestoException (io.prestosql.spi.PrestoException)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 StandardFunctionResolution (io.prestosql.spi.function.StandardFunctionResolution)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1