Skip to content

Commit

Permalink
Remove unused usages of SqlParser, TypeProvider, VariableAllocator
Browse files Browse the repository at this point in the history
  • Loading branch information
rschlussel committed Aug 29, 2024
1 parent 539a448 commit d6a42fc
Show file tree
Hide file tree
Showing 71 changed files with 178 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ private PlanRoot createLogicalPlanAndOptimize()
metadata,
planOptimizers,
planChecker,
sqlParser,
analyzerContext.getVariableAllocator(),
idAllocator,
stateMachine.getWarningCollector(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public class SqlQueryScheduler
private final Set<StageId> runtimeOptimizedStages = Collections.synchronizedSet(new HashSet<>());
private final PlanChecker planChecker;
private final Metadata metadata;
private final SqlParser sqlParser;

private final Map<StageId, StageExecutionAndScheduler> stageExecutions = new ConcurrentHashMap<>();
private final ExecutorService executor;
Expand Down Expand Up @@ -237,7 +236,6 @@ private SqlQueryScheduler(
this.variableAllocator = requireNonNull(variableAllocator, "variableAllocator is null");
this.planChecker = requireNonNull(planChecker, "planChecker is null");
this.metadata = requireNonNull(metadata, "metadata is null");
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
this.sectionExecutionFactory = requireNonNull(sectionExecutionFactory, "sectionExecutionFactory is null");
this.remoteTaskFactory = requireNonNull(remoteTaskFactory, "remoteTaskFactory is null");
this.splitSourceFactory = requireNonNull(splitSourceFactory, "splitSourceFactory is null");
Expand Down Expand Up @@ -596,7 +594,7 @@ private StreamingPlanSection tryCostBasedOptimize(StreamingPlanSection section)
.forEach(currentSubPlan -> {
Optional<PlanFragment> newPlanFragment = performRuntimeOptimizations(currentSubPlan);
if (newPlanFragment.isPresent()) {
planChecker.validatePlanFragment(newPlanFragment.get().getRoot(), session, metadata, sqlParser, TypeProvider.viewOf(variableAllocator.getVariables()), warningCollector);
planChecker.validatePlanFragment(newPlanFragment.get().getRoot(), session, metadata, warningCollector);
oldToNewFragment.put(currentSubPlan.getFragment(), newPlanFragment.get());
}
});
Expand Down
12 changes: 4 additions & 8 deletions presto-main/src/main/java/com/facebook/presto/sql/Optimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.facebook.presto.spi.eventlistener.PlanOptimizerInformation;
import com.facebook.presto.spi.plan.PlanNode;
import com.facebook.presto.spi.plan.PlanNodeIdAllocator;
import com.facebook.presto.sql.parser.SqlParser;
import com.facebook.presto.sql.planner.Plan;
import com.facebook.presto.sql.planner.PlannerUtils;
import com.facebook.presto.sql.planner.TypeProvider;
Expand Down Expand Up @@ -69,7 +68,6 @@ public enum PlanStage
private final PlanChecker planChecker;
private final Session session;
private final Metadata metadata;
private final SqlParser sqlParser;
private final VariableAllocator variableAllocator;
private final PlanNodeIdAllocator idAllocator;
private final WarningCollector warningCollector;
Expand All @@ -82,7 +80,6 @@ public Optimizer(
Metadata metadata,
List<PlanOptimizer> planOptimizers,
PlanChecker planChecker,
SqlParser sqlParser,
VariableAllocator variableAllocator,
PlanNodeIdAllocator idAllocator,
WarningCollector warningCollector,
Expand All @@ -94,7 +91,6 @@ public Optimizer(
this.planOptimizers = requireNonNull(planOptimizers, "planOptimizers is null");
this.planChecker = requireNonNull(planChecker, "planChecker is null");
this.metadata = requireNonNull(metadata, "metadata is null");
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
this.variableAllocator = requireNonNull(variableAllocator, "variableAllocator is null");
this.idAllocator = requireNonNull(idAllocator, "idAllocator is null");
this.warningCollector = requireNonNull(warningCollector, "warningCollector is null");
Expand All @@ -105,7 +101,7 @@ public Optimizer(

public Plan validateAndOptimizePlan(PlanNode root, PlanStage stage)
{
planChecker.validateIntermediatePlan(root, session, metadata, sqlParser, TypeProvider.viewOf(variableAllocator.getVariables()), warningCollector);
planChecker.validateIntermediatePlan(root, session, metadata, warningCollector);

boolean enableVerboseRuntimeStats = SystemSessionProperties.isVerboseRuntimeStatsEnabled(session);
if (stage.ordinal() >= OPTIMIZED.ordinal()) {
Expand All @@ -128,7 +124,7 @@ public Plan validateAndOptimizePlan(PlanNode root, PlanStage stage)

if (stage.ordinal() >= OPTIMIZED_AND_VALIDATED.ordinal()) {
// make sure we produce a valid plan after optimizations run. This is mainly to catch programming errors
planChecker.validateFinalPlan(root, session, metadata, sqlParser, TypeProvider.viewOf(variableAllocator.getVariables()), warningCollector);
planChecker.validateFinalPlan(root, session, metadata, warningCollector);
}

TypeProvider types = TypeProvider.viewOf(variableAllocator.getVariables());
Expand Down Expand Up @@ -168,8 +164,8 @@ private void collectOptimizerInformation(PlanOptimizer optimizer, PlanNode oldNo
boolean isTriggered = planOptimizerResult.isOptimizerTriggered();
boolean isApplicable =
isTriggered ||
!optimizer.isEnabled(session) && isVerboseOptimizerInfoEnabled(session) &&
optimizer.isApplicable(oldNode, session, TypeProvider.viewOf(variableAllocator.getVariables()), variableAllocator, idAllocator, warningCollector);
!optimizer.isEnabled(session) && isVerboseOptimizerInfoEnabled(session) &&
optimizer.isApplicable(oldNode, session, TypeProvider.viewOf(variableAllocator.getVariables()), variableAllocator, idAllocator, warningCollector);
boolean isCostBased = isTriggered && optimizer.isCostBased(session);
String statsSource = optimizer.getStatsSource();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public Plan getLogicalPlan(Session session, Statement statement, List<Expression
metadata,
planOptimizers,
planChecker,
sqlParser,
planVariableAllocator,
idAllocator,
warningCollector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.facebook.presto.spi.plan.ValuesNode;
import com.facebook.presto.spi.relation.RowExpression;
import com.facebook.presto.spi.relation.VariableReferenceExpression;
import com.facebook.presto.sql.parser.SqlParser;
import com.facebook.presto.sql.planner.plan.ExchangeNode;
import com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode;
import com.facebook.presto.sql.planner.plan.MetadataDeleteNode;
Expand All @@ -52,7 +51,6 @@
import com.google.common.collect.ImmutableSet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -97,19 +95,15 @@ public abstract class BasePlanFragmenter
private final StatsAndCosts statsAndCosts;
private final PlanChecker planChecker;
private final WarningCollector warningCollector;
private final SqlParser sqlParser;
private final Set<PlanNodeId> outputTableWriterNodeIds;
private final StatisticsAggregationPlanner statisticsAggregationPlanner;

private Map<String, TableScanNode> cteNameToTableScanMap = new HashMap<>();

public BasePlanFragmenter(
Session session,
Metadata metadata,
StatsAndCosts statsAndCosts,
PlanChecker planChecker,
WarningCollector warningCollector,
SqlParser sqlParser,
PlanNodeIdAllocator idAllocator,
VariableAllocator variableAllocator,
Set<PlanNodeId> outputTableWriterNodeIds)
Expand All @@ -119,7 +113,6 @@ public BasePlanFragmenter(
this.statsAndCosts = requireNonNull(statsAndCosts, "statsAndCosts is null");
this.planChecker = requireNonNull(planChecker, "planChecker is null");
this.warningCollector = requireNonNull(warningCollector, "warningCollector is null");
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
this.idAllocator = requireNonNull(idAllocator, "idAllocator is null");
this.variableAllocator = requireNonNull(variableAllocator, "variableAllocator is null");
this.outputTableWriterNodeIds = ImmutableSet.copyOf(requireNonNull(outputTableWriterNodeIds, "outputTableWriterNodeIds is null"));
Expand All @@ -143,7 +136,7 @@ private SubPlan buildFragment(PlanNode root, FragmentProperties properties, Plan
properties.getPartitionedSources());

Set<VariableReferenceExpression> fragmentVariableTypes = extractOutputVariables(root);
planChecker.validatePlanFragment(root, session, metadata, sqlParser, TypeProvider.fromVariables(fragmentVariableTypes), warningCollector);
planChecker.validatePlanFragment(root, session, metadata, warningCollector);

Set<PlanNodeId> tableWriterNodeIds = PlanFragmenterUtils.getTableWriterNodeIds(root);
boolean outputTableWriterFragment = tableWriterNodeIds.stream().anyMatch(outputTableWriterNodeIds::contains);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ else if (leftArgument instanceof VariableReferenceExpression && rightArgument in
return Optional.of(new Partitioning(metadata.isRefinedPartitioningOver(session, other.handle, this.handle) ? this.handle : other.handle, arguments.build()));
}

public Optional<Partitioning> translateRowExpression(Map<VariableReferenceExpression, RowExpression> inputToOutputMappings, Map<VariableReferenceExpression, RowExpression> assignments, TypeProvider types)
public Optional<Partitioning> translateRowExpression(Map<VariableReferenceExpression, RowExpression> inputToOutputMappings, Map<VariableReferenceExpression, RowExpression> assignments)
{
ImmutableList.Builder<RowExpression> newArguments = ImmutableList.builder();
for (RowExpression argument : arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.facebook.presto.spi.plan.PlanNodeId;
import com.facebook.presto.spi.plan.PlanNodeIdAllocator;
import com.facebook.presto.sql.analyzer.FeaturesConfig;
import com.facebook.presto.sql.parser.SqlParser;
import com.facebook.presto.sql.planner.BasePlanFragmenter.FragmentProperties;
import com.facebook.presto.sql.planner.plan.PlanFragmentId;
import com.facebook.presto.sql.planner.plan.SimplePlanRewriter;
Expand All @@ -49,17 +48,15 @@ public class PlanFragmenter
private final Metadata metadata;
private final NodePartitioningManager nodePartitioningManager;
private final QueryManagerConfig config;
private final SqlParser sqlParser;
private final PlanChecker distributedPlanChecker;
private final PlanChecker singleNodePlanChecker;

@Inject
public PlanFragmenter(Metadata metadata, NodePartitioningManager nodePartitioningManager, QueryManagerConfig queryManagerConfig, SqlParser sqlParser, FeaturesConfig featuresConfig)
public PlanFragmenter(Metadata metadata, NodePartitioningManager nodePartitioningManager, QueryManagerConfig queryManagerConfig, FeaturesConfig featuresConfig)
{
this.metadata = requireNonNull(metadata, "metadata is null");
this.nodePartitioningManager = requireNonNull(nodePartitioningManager, "nodePartitioningManager is null");
this.config = requireNonNull(queryManagerConfig, "queryManagerConfig is null");
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
this.distributedPlanChecker = new PlanChecker(requireNonNull(featuresConfig, "featuresConfig is null"), false);
this.singleNodePlanChecker = new PlanChecker(requireNonNull(featuresConfig, "featuresConfig is null"), true);
}
Expand All @@ -78,7 +75,6 @@ public SubPlan createSubPlans(Session session, Plan plan, boolean forceSingleNod
plan.getStatsAndCosts(),
forceSingleNode ? singleNodePlanChecker : distributedPlanChecker,
warningCollector,
sqlParser,
idAllocator,
variableAllocator,
getOutputTableWriterNodeIds(plan.getRoot()));
Expand All @@ -100,9 +96,9 @@ private static class Fragmenter
{
private int nextFragmentId = ROOT_FRAGMENT_ID + 1;

public Fragmenter(Session session, Metadata metadata, StatsAndCosts statsAndCosts, PlanChecker planChecker, WarningCollector warningCollector, SqlParser sqlParser, PlanNodeIdAllocator idAllocator, VariableAllocator variableAllocator, Set<PlanNodeId> outputTableWriterNodeIds)
public Fragmenter(Session session, Metadata metadata, StatsAndCosts statsAndCosts, PlanChecker planChecker, WarningCollector warningCollector, PlanNodeIdAllocator idAllocator, VariableAllocator variableAllocator, Set<PlanNodeId> outputTableWriterNodeIds)
{
super(session, metadata, statsAndCosts, planChecker, warningCollector, sqlParser, idAllocator, variableAllocator, outputTableWriterNodeIds);
super(session, metadata, statsAndCosts, planChecker, warningCollector, idAllocator, variableAllocator, outputTableWriterNodeIds);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public PlanOptimizers(
statsCalculator,
estimatedExchangesCostCalculator,
ImmutableSet.<Rule<?>>builder()
.addAll(new InlineSqlFunctions(metadata, sqlParser).rules())
.addAll(new InlineSqlFunctions(metadata).rules())
.build()),
new IterativeOptimizer(
metadata,
Expand Down Expand Up @@ -578,7 +578,7 @@ public PlanOptimizers(
statsCalculator,
estimatedExchangesCostCalculator,
ImmutableSet.of(new LeftJoinNullFilterToSemiJoin(metadata.getFunctionAndTypeManager()))),
new KeyBasedSampler(metadata, sqlParser),
new KeyBasedSampler(metadata),
new IterativeOptimizer(
metadata,
ruleStats,
Expand Down Expand Up @@ -666,7 +666,7 @@ public PlanOptimizers(
statsCalculator,
estimatedExchangesCostCalculator,
ImmutableSet.<Rule<?>>builder()
.addAll(new InlineSqlFunctions(metadata, sqlParser).rules())
.addAll(new InlineSqlFunctions(metadata).rules())
.build()));

builder.add(new JoinPrefilter(metadata));
Expand Down Expand Up @@ -846,7 +846,7 @@ public PlanOptimizers(
ImmutableSet.of(new PushTableWriteThroughUnion()))); // Must run before AddExchanges
builder.add(new CteProjectionAndPredicatePushDown(metadata)); // must run before PhysicalCteOptimizer
builder.add(new PhysicalCteOptimizer(metadata)); // Must run before AddExchanges
builder.add(new StatsRecordingPlanOptimizer(optimizerStats, new AddExchanges(metadata, sqlParser, partitioningProviderManager, featuresConfig.isNativeExecutionEnabled())));
builder.add(new StatsRecordingPlanOptimizer(optimizerStats, new AddExchanges(metadata, partitioningProviderManager, featuresConfig.isNativeExecutionEnabled())));
}

//noinspection UnusedAssignment
Expand Down Expand Up @@ -882,10 +882,10 @@ public PlanOptimizers(
// MergeJoinForSortedInputOptimizer can avoid the local exchange for a join operation
// Should be placed after AddExchanges, but before AddLocalExchange
// To replace the JoinNode to MergeJoin ahead of AddLocalExchange to avoid adding extra local exchange
builder.add(new MergeJoinForSortedInputOptimizer(metadata, sqlParser));
builder.add(new MergeJoinForSortedInputOptimizer(metadata));

// Optimizers above this don't understand local exchanges, so be careful moving this.
builder.add(new AddLocalExchanges(metadata, sqlParser, featuresConfig.isNativeExecutionEnabled()));
builder.add(new AddLocalExchanges(metadata, featuresConfig.isNativeExecutionEnabled()));

// Optimizers above this do not need to care about aggregations with the type other than SINGLE
// This optimizer must be run after all exchange-related optimizers
Expand Down Expand Up @@ -944,7 +944,7 @@ public PlanOptimizers(
statsCalculator,
costCalculator,
ImmutableList.of(),
ImmutableSet.of(new RuntimeReorderJoinSides(metadata, sqlParser))));
ImmutableSet.of(new RuntimeReorderJoinSides(metadata))));
this.runtimeOptimizers = runtimeBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ public final class VariablesExtractor
{
private VariablesExtractor() {}

public static Set<VariableReferenceExpression> extractUnique(PlanNode node, TypeProvider types)
public static Set<VariableReferenceExpression> extractUnique(PlanNode node)
{
ImmutableSet.Builder<VariableReferenceExpression> unique = ImmutableSet.builder();
extractExpressions(node).forEach(expression -> unique.addAll(extractUniqueVariableInternal(expression, types)));
extractExpressions(node).forEach(expression -> unique.addAll(extractUniqueVariableInternal(expression)));

return unique.build();
}

public static Set<VariableReferenceExpression> extractUniqueNonRecursive(PlanNode node, TypeProvider types)
public static Set<VariableReferenceExpression> extractUniqueNonRecursive(PlanNode node)
{
ImmutableSet.Builder<VariableReferenceExpression> uniqueVariables = ImmutableSet.builder();
extractExpressionsNonRecursive(node).forEach(expression -> uniqueVariables.addAll(extractUniqueVariableInternal(expression, types)));
extractExpressionsNonRecursive(node).forEach(expression -> uniqueVariables.addAll(extractUniqueVariableInternal(expression)));

return uniqueVariables.build();
}

public static Set<VariableReferenceExpression> extractUnique(PlanNode node, Lookup lookup, TypeProvider types)
public static Set<VariableReferenceExpression> extractUnique(PlanNode node, Lookup lookup)
{
ImmutableSet.Builder<VariableReferenceExpression> unique = ImmutableSet.builder();
extractExpressions(node, lookup).forEach(expression -> unique.addAll(extractUniqueVariableInternal(expression, types)));
extractExpressions(node, lookup).forEach(expression -> unique.addAll(extractUniqueVariableInternal(expression)));
return unique.build();
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public static Set<VariableReferenceExpression> extractOutputVariables(PlanNode p
.collect(toImmutableSet());
}

private static Set<VariableReferenceExpression> extractUniqueVariableInternal(RowExpression expression, TypeProvider types)
private static Set<VariableReferenceExpression> extractUniqueVariableInternal(RowExpression expression)
{
return extractUnique(expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static Map<VariableReferenceExpression, Aggregation> inputsAsOutputs(Map
if (!(aggregation.getArguments().size() == 1 && !aggregation.getOrderBy().isPresent() && !aggregation.getFilter().isPresent())) {
return ImmutableMap.of();
}
VariableReferenceExpression input = getOnlyElement(extractAggregationUniqueVariables(entry.getValue(), types));
VariableReferenceExpression input = getOnlyElement(extractAggregationUniqueVariables(entry.getValue()));
// Return type of intermediate aggregation is the same as the input type.
RowExpression argumentExpr = aggregation.getCall().getArguments().get(0);
Type returnType = argumentExpr.getType();
Expand Down
Loading

0 comments on commit d6a42fc

Please sign in to comment.