Skip to content

Commit

Permalink
Inline LocalQueryRunner#translateExpressions
Browse files Browse the repository at this point in the history
This is only used in tests to construct a plan optimizer that
translates all OriginalExpression in planNodes to RowExpression.
And all the information obtained from public methods of
LocalQueryRunner. Thus it doesn't have to be a method of
LocalQueryRunner.
  • Loading branch information
wenleix committed Sep 5, 2019
1 parent ecdbbb3 commit 523501d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,8 @@
import com.facebook.presto.sql.planner.Plan;
import com.facebook.presto.sql.planner.PlanFragmenter;
import com.facebook.presto.sql.planner.PlanOptimizers;
import com.facebook.presto.sql.planner.RuleStatsRecorder;
import com.facebook.presto.sql.planner.SubPlan;
import com.facebook.presto.sql.planner.iterative.IterativeOptimizer;
import com.facebook.presto.sql.planner.optimizations.PlanOptimizer;
import com.facebook.presto.sql.planner.optimizations.TranslateExpressions;
import com.facebook.presto.sql.planner.planPrinter.PlanPrinter;
import com.facebook.presto.sql.planner.sanity.PlanSanityChecker;
import com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator;
Expand Down Expand Up @@ -914,16 +911,4 @@ private static List<TableScanNode> findTableScanNodes(PlanNode node)
.where(TableScanNode.class::isInstance)
.findAll();
}

public PlanOptimizer translateExpressions()
{
// Translate all OriginalExpression in planNodes to RowExpression so that we can do plan pattern asserting and printing on RowExpression only.
return new IterativeOptimizer(
new RuleStatsRecorder(),
getStatsCalculator(),
getCostCalculator(),
new ImmutableSet.Builder()
.addAll(new TranslateExpressions(getMetadata(), getSqlParser()).rules())
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.facebook.presto.sql.planner.iterative.IterativeOptimizer;
import com.facebook.presto.sql.planner.iterative.Rule;
import com.facebook.presto.sql.planner.optimizations.PlanOptimizer;
import com.facebook.presto.sql.planner.optimizations.TranslateExpressions;
import com.facebook.presto.sql.planner.plan.ProjectNode;
import com.facebook.presto.testing.LocalQueryRunner;
import com.facebook.presto.tpch.TpchConnectorFactory;
Expand Down Expand Up @@ -127,7 +128,14 @@ private static Plan createPlan(LocalQueryRunner queryRunner, Session session, St
queryRunner.getCostCalculator(),
ImmutableSet.copyOf(rules));

return queryRunner.createPlan(session, sql, ImmutableList.of(optimizer, queryRunner.translateExpressions()), LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, warningCollector);
// Translate all OriginalExpression in planNodes to RowExpression so that we can do plan pattern asserting and printing on RowExpression only.
PlanOptimizer expressionTranslator = new IterativeOptimizer(
new RuleStatsRecorder(),
queryRunner.getStatsCalculator(),
queryRunner.getCostCalculator(),
ImmutableSet.copyOf(new TranslateExpressions(queryRunner.getMetadata(), queryRunner.getSqlParser()).rules()));

return queryRunner.createPlan(session, sql, ImmutableList.of(optimizer, expressionTranslator), LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, warningCollector);
}

public static List<PrestoWarning> createTestWarnings(int numberOfWarnings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections;
import com.facebook.presto.sql.planner.optimizations.PlanOptimizer;
import com.facebook.presto.sql.planner.optimizations.PruneUnreferencedOutputs;
import com.facebook.presto.sql.planner.optimizations.TranslateExpressions;
import com.facebook.presto.sql.planner.optimizations.UnaliasSymbolReferences;
import com.facebook.presto.testing.LocalQueryRunner;
import com.facebook.presto.tpch.TpchConnectorFactory;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected void assertPlan(String sql, LogicalPlanner.Stage stage, PlanMatchPatte
sql,
ImmutableList.<PlanOptimizer>builder()
.addAll(optimizers)
.add(queryRunner.translateExpressions()).build(), // To avoid assert plan failure not printing out plan (#12885)
.add(getExpressionTranslator()).build(), // To avoid assert plan failure not printing out plan (#12885)
stage,
WarningCollector.NOOP);
PlanAssert.assertPlan(transactionSession, queryRunner.getMetadata(), queryRunner.getStatsCalculator(), actualPlan, pattern);
Expand Down Expand Up @@ -167,7 +168,7 @@ protected void assertMinimallyOptimizedPlan(@Language("SQL") String sql, PlanMat
queryRunner.getStatsCalculator(),
queryRunner.getCostCalculator(),
ImmutableSet.of(new RemoveRedundantIdentityProjections())),
queryRunner.translateExpressions()); // To avoid assert plan failure not printing out plan (#12885)
getExpressionTranslator()); // To avoid assert plan failure not printing out plan (#12885)

assertPlan(sql, LogicalPlanner.Stage.OPTIMIZED, pattern, optimizers);
}
Expand Down Expand Up @@ -216,6 +217,16 @@ protected Metadata getMetadata()
return getQueryRunner().getMetadata();
}

// Translate all OriginalExpression in planNodes to RowExpression so that we can do plan pattern asserting and printing on RowExpression only.
protected PlanOptimizer getExpressionTranslator()
{
return new IterativeOptimizer(
new RuleStatsRecorder(),
getQueryRunner().getStatsCalculator(),
getQueryRunner().getCostCalculator(),
ImmutableSet.copyOf(new TranslateExpressions(getMetadata(), getQueryRunner().getSqlParser()).rules()));
}

public interface LocalQueryRunnerSupplier
{
LocalQueryRunner get()
Expand Down

0 comments on commit 523501d

Please sign in to comment.