Search in sources :

Example 1 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator in project presto by prestodb.

the class PrestoSparkQueryPlanner method createQueryPlan.

public PlanAndMore createQueryPlan(Session session, PreparedQuery preparedQuery, WarningCollector warningCollector) {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), preparedQuery.getParameters(), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(false, session, optimizers.getPlanningTimeOptimizers(), idAllocator, metadata, sqlParser, statsCalculator, costCalculator, warningCollector, planChecker);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    Plan plan = logicalPlanner.plan(analysis, OPTIMIZED_AND_VALIDATED);
    List<Input> inputs = new InputExtractor(metadata, session).extractInputs(plan.getRoot());
    Optional<Output> output = new OutputExtractor().extractOutput(plan.getRoot());
    Optional<QueryType> queryType = getQueryType(preparedQuery.getStatement().getClass());
    List<String> columnNames = ((OutputNode) plan.getRoot()).getColumnNames();
    return new PlanAndMore(plan, Optional.ofNullable(analysis.getUpdateType()), columnNames, ImmutableSet.copyOf(inputs), output, queryType);
}
Also used : OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) InputExtractor(com.facebook.presto.sql.planner.InputExtractor) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) Plan(com.facebook.presto.sql.planner.Plan) Input(com.facebook.presto.execution.Input) OutputExtractor(com.facebook.presto.sql.planner.OutputExtractor) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) Analysis(com.facebook.presto.sql.analyzer.Analysis) Output(com.facebook.presto.execution.Output) StatementUtils.getQueryType(com.facebook.presto.util.StatementUtils.getQueryType) QueryType(com.facebook.presto.spi.resourceGroups.QueryType)

Example 2 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator in project presto by prestodb.

the class QueryExplainer method getDistributedPlan.

public SubPlan getDistributedPlan(Session session, Statement statement, List<Expression> parameters, WarningCollector warningCollector) {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    Plan plan = getLogicalPlan(session, statement, parameters, warningCollector, idAllocator);
    return planFragmenter.createSubPlans(session, plan, false, idAllocator, warningCollector);
}
Also used : PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) IOPlanPrinter.textIOPlan(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.textIOPlan) PlanPrinter.graphvizDistributedPlan(com.facebook.presto.sql.planner.planPrinter.PlanPrinter.graphvizDistributedPlan) PlanPrinter.jsonDistributedPlan(com.facebook.presto.sql.planner.planPrinter.PlanPrinter.jsonDistributedPlan) Plan(com.facebook.presto.sql.planner.Plan) SubPlan(com.facebook.presto.sql.planner.SubPlan) PlanPrinter.graphvizLogicalPlan(com.facebook.presto.sql.planner.planPrinter.PlanPrinter.graphvizLogicalPlan) PlanPrinter.jsonLogicalPlan(com.facebook.presto.sql.planner.planPrinter.PlanPrinter.jsonLogicalPlan)

Example 3 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator 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;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) SqlParser(com.facebook.presto.sql.parser.SqlParser) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) DynamicFiltersChecker(com.facebook.presto.sql.planner.sanity.DynamicFiltersChecker) RemoveUnsupportedDynamicFilters(com.facebook.presto.sql.planner.iterative.rule.RemoveUnsupportedDynamicFilters)

Example 4 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator in project presto by prestodb.

the class TestRemoveUnsupportedDynamicFilters method setup.

@BeforeClass
public void setup() {
    metadata = getQueryRunner().getMetadata();
    logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata.getFunctionAndTypeManager()), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    builder = new PlanBuilder(getQueryRunner().getDefaultSession(), new PlanNodeIdAllocator(), metadata);
    ConnectorId connectorId = getCurrentConnectorId();
    TableHandle lineitemTableHandle = new TableHandle(connectorId, new TpchTableHandle("lineitem", 1.0), TestingTransactionHandle.create(), Optional.empty());
    lineitemOrderKeyVariable = builder.variable("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeyVariable), ImmutableMap.of(lineitemOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(connectorId, new TpchTableHandle("orders", 1.0), TestingTransactionHandle.create(), Optional.empty());
    ordersOrderKeyVariable = builder.variable("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeyVariable), ImmutableMap.of(ordersOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator in project presto by prestodb.

the class TestDynamicFiltersChecker method setup.

@BeforeClass
public void setup() {
    metadata = getQueryRunner().getMetadata();
    logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata.getFunctionAndTypeManager()), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    builder = new PlanBuilder(getQueryRunner().getDefaultSession(), new PlanNodeIdAllocator(), metadata);
    ConnectorId connectorId = getCurrentConnectorId();
    TableHandle lineitemTableHandle = new TableHandle(connectorId, new TpchTableHandle("lineitem", 1.0), TestingTransactionHandle.create(), Optional.empty());
    lineitemOrderKeyVariable = builder.variable("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeyVariable), ImmutableMap.of(lineitemOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(connectorId, new TpchTableHandle("orders", 1.0), TestingTransactionHandle.create(), Optional.empty());
    ordersOrderKeyVariable = builder.variable("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeyVariable), ImmutableMap.of(ordersOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)22 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)14 Test (org.testng.annotations.Test)9 PlanVariableAllocator (com.facebook.presto.sql.planner.PlanVariableAllocator)7 PlanNode (com.facebook.presto.spi.plan.PlanNode)5 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)5 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)4 ProjectionContext (com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext)4 Session (com.facebook.presto.Session)3 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)3 ConnectorId (com.facebook.presto.spi.ConnectorId)3 TableHandle (com.facebook.presto.spi.TableHandle)3 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)3 TpchColumnHandle (com.facebook.presto.tpch.TpchColumnHandle)3 TpchTableHandle (com.facebook.presto.tpch.TpchTableHandle)3 BeforeClass (org.testng.annotations.BeforeClass)3 Capture (com.facebook.presto.matching.Capture)2 Capture.newCapture (com.facebook.presto.matching.Capture.newCapture)2 Captures (com.facebook.presto.matching.Captures)2 Pattern (com.facebook.presto.matching.Pattern)2