use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestRemoveUnsupportedDynamicFilters method removeUnsupportedDynamicFilters.
PlanNode removeUnsupportedDynamicFilters(PlanNode root) {
return getQueryRunner().inTransaction(session -> {
// metadata.getCatalogHandle() registers the catalog for the transaction
session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
PlanNode rewrittenPlan = new RemoveUnsupportedDynamicFilters(metadata.getFunctionAndTypeManager()).optimize(root, session, TypeProvider.empty(), new PlanVariableAllocator(), new PlanNodeIdAllocator(), WarningCollector.NOOP);
new DynamicFiltersChecker().validate(rewrittenPlan, session, metadata, new SqlParser(), TypeProvider.empty(), WarningCollector.NOOP);
return rewrittenPlan;
});
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestWindowNode method setUp.
@BeforeClass
public void setUp() {
variableAllocator = new PlanVariableAllocator();
columnA = variableAllocator.newVariable("a", BIGINT);
columnB = variableAllocator.newVariable("b", BIGINT);
columnC = variableAllocator.newVariable("c", BIGINT);
sourceNode = new ValuesNode(Optional.empty(), newId(), ImmutableList.of(columnA, columnB, columnC), ImmutableList.of());
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestPinotPlanOptimizer method getOptimizedPlan.
protected PlanNode getOptimizedPlan(PinotConfig pinotConfig, PlanBuilder planBuilder, PlanNode originalPlan) {
PinotQueryGenerator pinotQueryGenerator = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution);
PinotPlanOptimizer optimizer = new PinotPlanOptimizer(pinotQueryGenerator, functionAndTypeManager, functionAndTypeManager, logicalRowExpressions, standardFunctionResolution);
return optimizer.optimize(originalPlan, new SessionHolder(pinotConfig).getConnectorSession(), new PlanVariableAllocator(), planBuilder.getIdAllocator());
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestDruidPlanOptimizer method testUnionAll.
@Test
public void testUnionAll() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
AggregationNode aggregationOne = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableOne, city, fare), variableAllocator, ImmutableList.of(city), fare);
AggregationNode aggregationTwo = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableTwo, city, fare), variableAllocator, ImmutableList.of(city), fare);
VariableReferenceExpression groupByColumn = variableAllocator.newVariable(city.getColumnName(), city.getColumnType());
VariableReferenceExpression sumColumn = variableAllocator.newVariable(fare.getColumnName(), fare.getColumnType());
PlanNode originalPlan = new UnionNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), ImmutableList.of(aggregationOne, aggregationTwo), ImmutableList.of(groupByColumn, sumColumn), ImmutableMap.of(groupByColumn, Stream.concat(aggregationOne.getGroupingKeys().stream(), aggregationTwo.getGroupingKeys().stream()).collect(toImmutableList()), sumColumn, ImmutableList.of(Iterables.getOnlyElement(aggregationOne.getAggregations().keySet()), Iterables.getOnlyElement(aggregationTwo.getAggregations().keySet()))));
PlanNode optimizedPlan = getOptimizedPlan(planBuilder, originalPlan);
PlanMatchPattern tableScanMatcherOne = DruidTableScanMatcher.match(druidTableOne.getTableName(), "SELECT \"city\", sum(fare) FROM \"realtimeOnly\" GROUP BY \"city\"");
PlanMatchPattern tableScanMatcherTwo = DruidTableScanMatcher.match(druidTableTwo.getTableName(), "SELECT \"city\", sum(fare) FROM \"hybrid\" GROUP BY \"city\"");
assertPlanMatch(optimizedPlan, PlanMatchPattern.union(tableScanMatcherOne, tableScanMatcherTwo), typeProvider);
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class SqlQueryExecution method doAnalyzeQuery.
private PlanRoot doAnalyzeQuery() {
// time analysis phase
stateMachine.beginAnalysis();
// plan query
LogicalPlanner logicalPlanner = new LogicalPlanner(false, stateMachine.getSession(), planOptimizers, idAllocator, metadata, sqlParser, statsCalculator, costCalculator, stateMachine.getWarningCollector(), planChecker);
Plan plan = getSession().getRuntimeStats().profileNanos(LOGICAL_PLANNER_TIME_NANOS, () -> logicalPlanner.plan(analysis));
queryPlan.set(plan);
// extract inputs
List<Input> inputs = new InputExtractor(metadata, stateMachine.getSession()).extractInputs(plan.getRoot());
stateMachine.setInputs(inputs);
// extract output
Optional<Output> output = new OutputExtractor().extractOutput(plan.getRoot());
stateMachine.setOutput(output);
// fragment the plan
// the variableAllocator is finally passed to SqlQueryScheduler for runtime cost-based optimizations
variableAllocator.set(new PlanVariableAllocator(plan.getTypes().allVariables()));
SubPlan fragmentedPlan = getSession().getRuntimeStats().profileNanos(FRAGMENT_PLAN_TIME_NANOS, () -> planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, idAllocator, variableAllocator.get(), stateMachine.getWarningCollector()));
// record analysis time
stateMachine.endAnalysis();
boolean explainAnalyze = analysis.getStatement() instanceof Explain && ((Explain) analysis.getStatement()).isAnalyze();
return new PlanRoot(fragmentedPlan, !explainAnalyze, extractConnectors(analysis));
}
Aggregations