Source:
<code>private RelationPlan createAnalyzePlan(Analysis analysis, Analyze analyzeStatement) { TableHandle targetTable = analysis.getTableHandle(analyzeStatement.getTable()); Map<String, Object> analyzeProperties = metadata.getAnalyzePropertyManager().getProperties( targetTable.getConnectorId(), targetTable.getConnectorId().getCatalogName(), analysis.getAnalyzeTableProperties(), session, metadata, analysis.getParameters()); AnalyzeTableMetadata analyzeTableMetadata = metadata.getAnalyzeTableMetadata(session, targetTable, analyzeProperties); targetTable = analyzeTableMetadata.getTableHandle(); 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(); for (ColumnMetadata column : analyzeTableMetadata.getTableMetadata().getColumns()) { Symbol symbol = symbolAllocator.newSymbol(column.getName(), column.getType()); tableScanOutputs.add(symbol); symbolToColumnHandle.put(symbol, columnHandles.get(column.getName())); columnNameToSymbol.put(column.getName(), symbol); } PlanNode planNode = new TableScanNode(idAllocator.getNextId(), targetTable, tableScanOutputs.build(), symbolToColumnHandle.build()); TableStatisticAggregation tableStatisticAggregation = statisticsAggregationPlanner.createStatisticsAggregation(analyzeTableMetadata.getStatisticsMetadata(), columnNameToSymbol.build()); StatisticAggregations statisticAggregations = tableStatisticAggregation.getAggregations(); List<Symbol> groupingSymbols = statisticAggregations.getGroupingSymbols(); <START> planNode = new AggregationNode( <END> idAllocator.getNextId(), planNode, statisticAggregations.getAggregations(), singleGroupingSet(groupingSymbols), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()); planNode = new AnalyzeFinishNode( idAllocator.getNextId(), planNode, new AnalyzeFinishNode.AnalyzeReference(targetTable), tableStatisticAggregation.getDescriptor()); return new RelationPlan(planNode, analysis.getScope(analyzeStatement), planNode.getOutputSymbols()); }</code><technical_language>inline</technical_language>

Target:
private RelationPlan createAnalyzePlan(Analysis analysis, Analyze analyzeStatement) { TableHandle targetTable = analysis.getAnalyzeTarget().get(); 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 = symbolAllocator.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.getConnectorId().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(), new TableScanNode(idAllocator.getNextId(), targetTable, tableScanOutputs.build(), symbolToColumnHandle.build()), statisticAggregations.getAggregations(), singleGroupingSet(groupingSymbols), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()), new StatisticsWriterNode.WriteStatisticsReference(targetTable), symbolAllocator.newSymbol("rows", BIGINT), tableStatisticsMetadata.getTableStatistics().contains(ROW_COUNT), tableStatisticAggregation.getDescriptor()); return new RelationPlan(planNode, analysis.getScope(analyzeStatement), planNode.getOutputSymbols()); }