Search in sources :

Example 1 with TableStatisticType

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

the class StatisticsAggregationPlanner method createStatisticsAggregation.

public TableStatisticAggregation createStatisticsAggregation(TableStatisticsMetadata statisticsMetadata, Map<String, Symbol> columnToSymbolMap) {
    StatisticAggregationsDescriptor.Builder<Symbol> descriptor = StatisticAggregationsDescriptor.builder();
    List<String> groupingColumns = statisticsMetadata.getGroupingColumns();
    List<Symbol> groupingSymbols = groupingColumns.stream().map(columnToSymbolMap::get).collect(toImmutableList());
    for (int i = 0; i < groupingSymbols.size(); i++) {
        descriptor.addGrouping(groupingColumns.get(i), groupingSymbols.get(i));
    }
    ImmutableMap.Builder<Symbol, AggregationNode.Aggregation> aggregations = ImmutableMap.builder();
    StandardFunctionResolution functionResolution = new FunctionResolution(metadata.getFunctionAndTypeManager());
    for (TableStatisticType type : statisticsMetadata.getTableStatistics()) {
        if (type != ROW_COUNT) {
            throw new PrestoException(NOT_SUPPORTED, "Table-wide statistic type not supported: " + type);
        }
        AggregationNode.Aggregation aggregation = new AggregationNode.Aggregation(new CallExpression("count", functionResolution.countFunction(), BIGINT, ImmutableList.of(), Optional.empty()), ImmutableList.of(), false, Optional.empty(), Optional.empty(), Optional.empty());
        Symbol symbol = planSymbolAllocator.newSymbol("rowCount", BIGINT);
        aggregations.put(symbol, aggregation);
        descriptor.addTableStatistic(ROW_COUNT, symbol);
    }
    for (ColumnStatisticMetadata columnStatisticMetadata : statisticsMetadata.getColumnStatistics()) {
        String columnName = columnStatisticMetadata.getColumnName();
        ColumnStatisticType statisticType = columnStatisticMetadata.getStatisticType();
        Symbol inputSymbol = columnToSymbolMap.get(columnName);
        verify(inputSymbol != null, "inputSymbol is null");
        Type inputType = planSymbolAllocator.getTypes().get(inputSymbol);
        verify(inputType != null, "inputType is null for symbol: %s", inputSymbol);
        ColumnStatisticsAggregation aggregation = createColumnAggregation(statisticType, inputSymbol, inputType);
        Symbol symbol = planSymbolAllocator.newSymbol(statisticType + ":" + columnName, aggregation.getOutputType());
        aggregations.put(symbol, aggregation.getAggregation());
        descriptor.addColumnStatistic(columnStatisticMetadata, symbol);
    }
    StatisticAggregations aggregation = new StatisticAggregations(aggregations.build(), groupingSymbols);
    return new TableStatisticAggregation(aggregation, descriptor.build());
}
Also used : ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) Symbol(io.prestosql.spi.plan.Symbol) PrestoException(io.prestosql.spi.PrestoException) AggregationNode(io.prestosql.spi.plan.AggregationNode) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) ImmutableMap(com.google.common.collect.ImmutableMap) StatisticAggregations(io.prestosql.sql.planner.plan.StatisticAggregations) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) Type(io.prestosql.spi.type.Type) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) StatisticAggregationsDescriptor(io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) CallExpression(io.prestosql.spi.relation.CallExpression)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 PrestoException (io.prestosql.spi.PrestoException)1 StandardFunctionResolution (io.prestosql.spi.function.StandardFunctionResolution)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1 Symbol (io.prestosql.spi.plan.Symbol)1 CallExpression (io.prestosql.spi.relation.CallExpression)1 ColumnStatisticMetadata (io.prestosql.spi.statistics.ColumnStatisticMetadata)1 ColumnStatisticType (io.prestosql.spi.statistics.ColumnStatisticType)1 TableStatisticType (io.prestosql.spi.statistics.TableStatisticType)1 Type (io.prestosql.spi.type.Type)1 StatisticAggregations (io.prestosql.sql.planner.plan.StatisticAggregations)1 StatisticAggregationsDescriptor (io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor)1 FunctionResolution (io.prestosql.sql.relational.FunctionResolution)1