Search in sources :

Example 1 with StatisticsWriterNode

use of io.prestosql.sql.planner.plan.StatisticsWriterNode in project hetu-core by openlookeng.

the class LogicalPlanner method createAnalyzePlan.

private RelationPlan createAnalyzePlan(Analysis analysis, Analyze analyzeStatement) {
    TableHandle targetTable = analysis.getAnalyzeTarget().get();
    // Plan table scan
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, targetTable);
    ImmutableList.Builder<Symbol> tableScanOutputs = ImmutableList.builder();
    ImmutableMap.Builder<Symbol, ColumnHandle> symbolToColumnHandle = ImmutableMap.builder();
    ImmutableMap.Builder<String, Symbol> columnNameToSymbol = ImmutableMap.builder();
    TableMetadata tableMetadata = metadata.getTableMetadata(session, targetTable);
    for (ColumnMetadata column : tableMetadata.getColumns()) {
        Symbol symbol = planSymbolAllocator.newSymbol(column.getName(), column.getType());
        tableScanOutputs.add(symbol);
        symbolToColumnHandle.put(symbol, columnHandles.get(column.getName()));
        columnNameToSymbol.put(column.getName(), symbol);
    }
    TableStatisticsMetadata tableStatisticsMetadata = metadata.getStatisticsCollectionMetadata(session, targetTable.getCatalogName().getCatalogName(), tableMetadata.getMetadata());
    TableStatisticAggregation tableStatisticAggregation = statisticsAggregationPlanner.createStatisticsAggregation(tableStatisticsMetadata, columnNameToSymbol.build());
    StatisticAggregations statisticAggregations = tableStatisticAggregation.getAggregations();
    List<Symbol> groupingSymbols = statisticAggregations.getGroupingSymbols();
    PlanNode planNode = new StatisticsWriterNode(idAllocator.getNextId(), new AggregationNode(idAllocator.getNextId(), TableScanNode.newInstance(idAllocator.getNextId(), targetTable, tableScanOutputs.build(), symbolToColumnHandle.build(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false), statisticAggregations.getAggregations(), singleGroupingSet(groupingSymbols), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty()), new StatisticsWriterNode.WriteStatisticsReference(targetTable), planSymbolAllocator.newSymbol("rows", BIGINT), tableStatisticsMetadata.getTableStatistics().contains(ROW_COUNT), tableStatisticAggregation.getDescriptor());
    return new RelationPlan(planNode, analysis.getScope(analyzeStatement), planNode.getOutputSymbols());
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) TableStatisticAggregation(io.prestosql.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Symbol(io.prestosql.spi.plan.Symbol) StatisticsWriterNode(io.prestosql.sql.planner.plan.StatisticsWriterNode) AggregationNode(io.prestosql.spi.plan.AggregationNode) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) StatisticAggregations(io.prestosql.sql.planner.plan.StatisticAggregations) PlanNode(io.prestosql.spi.plan.PlanNode) TableHandle(io.prestosql.spi.metadata.TableHandle) UUID(java.util.UUID)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 TableMetadata (io.prestosql.metadata.TableMetadata)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)1 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)1 TableHandle (io.prestosql.spi.metadata.TableHandle)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1 PlanNode (io.prestosql.spi.plan.PlanNode)1 Symbol (io.prestosql.spi.plan.Symbol)1 TableStatisticsMetadata (io.prestosql.spi.statistics.TableStatisticsMetadata)1 TableStatisticAggregation (io.prestosql.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation)1 StatisticAggregations (io.prestosql.sql.planner.plan.StatisticAggregations)1 StatisticsWriterNode (io.prestosql.sql.planner.plan.StatisticsWriterNode)1 UUID (java.util.UUID)1