use of com.facebook.presto.sql.planner.plan.StatisticsWriterNode in project presto by prestodb.
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<VariableReferenceExpression> tableScanOutputsBuilder = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> variableToColumnHandle = ImmutableMap.builder();
ImmutableMap.Builder<String, VariableReferenceExpression> columnNameToVariable = ImmutableMap.builder();
TableMetadata tableMetadata = metadata.getTableMetadata(session, targetTable);
for (ColumnMetadata column : tableMetadata.getColumns()) {
VariableReferenceExpression variable = variableAllocator.newVariable(getSourceLocation(analyzeStatement), column.getName(), column.getType());
tableScanOutputsBuilder.add(variable);
variableToColumnHandle.put(variable, columnHandles.get(column.getName()));
columnNameToVariable.put(column.getName(), variable);
}
List<VariableReferenceExpression> tableScanOutputs = tableScanOutputsBuilder.build();
TableStatisticsMetadata tableStatisticsMetadata = metadata.getStatisticsCollectionMetadata(session, targetTable.getConnectorId().getCatalogName(), tableMetadata.getMetadata());
TableStatisticAggregation tableStatisticAggregation = statisticsAggregationPlanner.createStatisticsAggregation(tableStatisticsMetadata, columnNameToVariable.build(), true);
StatisticAggregations statisticAggregations = tableStatisticAggregation.getAggregations();
PlanNode planNode = new StatisticsWriterNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), new AggregationNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), new TableScanNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), targetTable, tableScanOutputs, variableToColumnHandle.build(), TupleDomain.all(), TupleDomain.all()), statisticAggregations.getAggregations(), singleGroupingSet(statisticAggregations.getGroupingVariables()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()), targetTable, variableAllocator.newVariable(getSourceLocation(analyzeStatement), "rows", BIGINT), tableStatisticsMetadata.getTableStatistics().contains(ROW_COUNT), tableStatisticAggregation.getDescriptor());
return new RelationPlan(planNode, analysis.getScope(analyzeStatement), planNode.getOutputVariables());
}
Aggregations