Search in sources :

Example 26 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class SqlQueryScheduler method performRuntimeOptimizations.

private Optional<PlanFragment> performRuntimeOptimizations(StreamingSubPlan subPlan) {
    PlanFragment fragment = subPlan.getFragment();
    PlanNode newRoot = fragment.getRoot();
    for (PlanOptimizer optimizer : runtimePlanOptimizers) {
        newRoot = optimizer.optimize(newRoot, session, variableAllocator.getTypes(), variableAllocator, idAllocator, warningCollector);
    }
    if (newRoot != fragment.getRoot()) {
        return Optional.of(// even if the root's outputVariable layout is changed.
        new PlanFragment(fragment.getId(), newRoot, fragment.getVariables(), fragment.getPartitioning(), scheduleOrder(newRoot), fragment.getPartitioningScheme(), fragment.getStageExecutionDescriptor(), fragment.isOutputTableWriterFragment(), fragment.getStatsAndCosts(), Optional.of(jsonFragmentPlan(newRoot, fragment.getVariables(), functionAndTypeManager, session))));
    }
    return Optional.empty();
}
Also used : PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanFragment(com.facebook.presto.sql.planner.PlanFragment)

Example 27 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestPhasedExecutionSchedule method testJoinWithDeepSources.

@Test
public void testJoinWithDeepSources() {
    PlanFragment buildSourceFragment = createTableScanPlanFragment("buildSource");
    PlanFragment buildMiddleFragment = createExchangePlanFragment("buildMiddle", buildSourceFragment);
    PlanFragment buildTopFragment = createExchangePlanFragment("buildTop", buildMiddleFragment);
    PlanFragment probeSourceFragment = createTableScanPlanFragment("probeSource");
    PlanFragment probeMiddleFragment = createExchangePlanFragment("probeMiddle", probeSourceFragment);
    PlanFragment probeTopFragment = createExchangePlanFragment("probeTop", probeMiddleFragment);
    PlanFragment joinFragment = createJoinPlanFragment(INNER, "join", buildTopFragment, probeTopFragment);
    List<Set<PlanFragmentId>> phases = PhasedExecutionSchedule.extractPhases(ImmutableList.of(joinFragment, buildTopFragment, buildMiddleFragment, buildSourceFragment, probeTopFragment, probeMiddleFragment, probeSourceFragment));
    assertEquals(phases, ImmutableList.of(ImmutableSet.of(joinFragment.getId()), ImmutableSet.of(buildTopFragment.getId()), ImmutableSet.of(buildMiddleFragment.getId()), ImmutableSet.of(buildSourceFragment.getId()), ImmutableSet.of(probeTopFragment.getId()), ImmutableSet.of(probeMiddleFragment.getId()), ImmutableSet.of(probeSourceFragment.getId())));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) Test(org.testng.annotations.Test)

Example 28 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestSourcePartitionedScheduler method createPlan.

private static SubPlan createPlan() {
    VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", VARCHAR);
    // table scan with splitCount splits
    TableScanNode tableScan = new TableScanNode(Optional.empty(), TABLE_SCAN_NODE_ID, new TableHandle(CONNECTOR_ID, new TestingTableHandle(), TestingTransactionHandle.create(), Optional.empty()), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all());
    RemoteSourceNode remote = new RemoteSourceNode(Optional.empty(), new PlanNodeId("remote_id"), new PlanFragmentId(0), ImmutableList.of(), false, Optional.empty(), GATHER);
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId(0), new JoinNode(Optional.empty(), new PlanNodeId("join_id"), INNER, tableScan, remote, ImmutableList.of(), ImmutableList.<VariableReferenceExpression>builder().addAll(tableScan.getOutputVariables()).addAll(remote.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()), ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(TABLE_SCAN_NODE_ID), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), StageExecutionDescriptor.ungroupedExecution(), false, StatsAndCosts.empty(), Optional.empty());
    return new SubPlan(testFragment, ImmutableList.of());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) TableHandle(com.facebook.presto.spi.TableHandle) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) SubPlan(com.facebook.presto.sql.planner.SubPlan)

Example 29 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestHttpRemoteTask method createHttpRemoteTaskFactory.

private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource, boolean useThriftEncoding) throws Exception {
    Bootstrap app = new Bootstrap(new JsonModule(), new SmileModule(), new ThriftCodecModule(), new HandleJsonModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(JsonMapper.class);
            binder.bind(ThriftMapper.class);
            configBinder(binder).bindConfig(FeaturesConfig.class);
            FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
            binder.bind(TypeManager.class).toInstance(functionAndTypeManager);
            jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
            newSetBinder(binder, Type.class);
            smileCodecBinder(binder).bindSmileCodec(TaskStatus.class);
            smileCodecBinder(binder).bindSmileCodec(TaskInfo.class);
            smileCodecBinder(binder).bindSmileCodec(TaskUpdateRequest.class);
            smileCodecBinder(binder).bindSmileCodec(PlanFragment.class);
            smileCodecBinder(binder).bindSmileCodec(MetadataUpdates.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskStatus.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskUpdateRequest.class);
            jsonCodecBinder(binder).bindJsonCodec(PlanFragment.class);
            jsonCodecBinder(binder).bindJsonCodec(MetadataUpdates.class);
            jsonBinder(binder).addKeySerializerBinding(VariableReferenceExpression.class).to(Serialization.VariableReferenceExpressionSerializer.class);
            jsonBinder(binder).addKeyDeserializerBinding(VariableReferenceExpression.class).to(Serialization.VariableReferenceExpressionDeserializer.class);
            thriftCodecBinder(binder).bindThriftCodec(TaskStatus.class);
        }

        @Provides
        private HttpRemoteTaskFactory createHttpRemoteTaskFactory(JsonMapper jsonMapper, ThriftMapper thriftMapper, JsonCodec<TaskStatus> taskStatusJsonCodec, SmileCodec<TaskStatus> taskStatusSmileCodec, ThriftCodec<TaskStatus> taskStatusThriftCodec, JsonCodec<TaskInfo> taskInfoJsonCodec, SmileCodec<TaskInfo> taskInfoSmileCodec, JsonCodec<TaskUpdateRequest> taskUpdateRequestJsonCodec, SmileCodec<TaskUpdateRequest> taskUpdateRequestSmileCodec, JsonCodec<PlanFragment> planFragmentJsonCodec, SmileCodec<PlanFragment> planFragmentSmileCodec, JsonCodec<MetadataUpdates> metadataUpdatesJsonCodec, SmileCodec<MetadataUpdates> metadataUpdatesSmileCodec) {
            JaxrsTestingHttpProcessor jaxrsTestingHttpProcessor = new JaxrsTestingHttpProcessor(URI.create("http://fake.invalid/"), testingTaskResource, jsonMapper, thriftMapper);
            TestingHttpClient testingHttpClient = new TestingHttpClient(jaxrsTestingHttpProcessor.setTrace(TRACE_HTTP));
            testingTaskResource.setHttpClient(testingHttpClient);
            return new HttpRemoteTaskFactory(new QueryManagerConfig(), TASK_MANAGER_CONFIG, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusJsonCodec, taskStatusSmileCodec, taskStatusThriftCodec, taskInfoJsonCodec, taskInfoSmileCodec, taskUpdateRequestJsonCodec, taskUpdateRequestSmileCodec, planFragmentJsonCodec, planFragmentSmileCodec, metadataUpdatesJsonCodec, metadataUpdatesSmileCodec, new RemoteTaskStats(), new InternalCommunicationConfig().setThriftTransportEnabled(useThriftEncoding), createTestMetadataManager(), new TestQueryManager());
        }
    });
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("test", new TestingHandleResolver());
    return injector.getInstance(HttpRemoteTaskFactory.class);
}
Also used : TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) HandleResolver(com.facebook.presto.metadata.HandleResolver) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ThriftMapper(com.facebook.airlift.jaxrs.thrift.ThriftMapper) TaskTestUtils.createPlanFragment(com.facebook.presto.execution.TaskTestUtils.createPlanFragment) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) JsonMapper(com.facebook.airlift.jaxrs.JsonMapper) TaskInfo(com.facebook.presto.execution.TaskInfo) MetadataUpdates(com.facebook.presto.metadata.MetadataUpdates) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) Binder(com.google.inject.Binder) ThriftCodecBinder.thriftCodecBinder(com.facebook.drift.codec.guice.ThriftCodecBinder.thriftCodecBinder) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) SmileCodecBinder.smileCodecBinder(com.facebook.airlift.json.smile.SmileCodecBinder.smileCodecBinder) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) InternalCommunicationConfig(com.facebook.presto.server.InternalCommunicationConfig) ThriftCodecModule(com.facebook.drift.codec.guice.ThriftCodecModule) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) JaxrsTestingHttpProcessor(com.facebook.airlift.jaxrs.testing.JaxrsTestingHttpProcessor) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Injector(com.google.inject.Injector) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) TestQueryManager(com.facebook.presto.execution.TestQueryManager) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) TaskStatus(com.facebook.presto.execution.TaskStatus) Provides(com.google.inject.Provides) JsonModule(com.facebook.airlift.json.JsonModule) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) MediaType(javax.ws.rs.core.MediaType) Type(com.facebook.presto.common.type.Type) SmileModule(com.facebook.airlift.json.smile.SmileModule) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) JsonModule(com.facebook.airlift.json.JsonModule) SmileModule(com.facebook.airlift.json.smile.SmileModule) ThriftCodecModule(com.facebook.drift.codec.guice.ThriftCodecModule) Module(com.google.inject.Module) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule)

Example 30 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestPlanPrinter method domainToPrintedScan.

// Creates a trivial TableScan with the given domain on some column
private String domainToPrintedScan(VariableReferenceExpression variable, ColumnHandle colHandle, Domain domain) {
    TupleDomain<ColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.<ColumnHandle, Domain>builder().put(colHandle, domain).build());
    TableScanNode scanNode = PLAN_BUILDER.tableScan(TABLE_HANDLE_WITH_LAYOUT, ImmutableList.of(variable), ImmutableMap.of(variable, colHandle), tupleDomain, tupleDomain);
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId(0), scanNode, ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(scanNode.getId()), new PartitioningScheme(Partitioning.create(SOURCE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), StageExecutionDescriptor.ungroupedExecution(), false, StatsAndCosts.empty(), Optional.empty());
    return PlanPrinter.textPlanFragment(testFragment, FUNCTION_AND_TYPE_MANAGER, TEST_SESSION, false);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment)

Aggregations

PlanFragment (com.facebook.presto.sql.planner.PlanFragment)30 PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)15 ImmutableSet (com.google.common.collect.ImmutableSet)12 Set (java.util.Set)12 PartitioningScheme (com.facebook.presto.sql.planner.PartitioningScheme)7 RemoteSourceNode (com.facebook.presto.sql.planner.plan.RemoteSourceNode)6 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 PlanNode (com.facebook.presto.spi.plan.PlanNode)5 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)5 SubPlan (com.facebook.presto.sql.planner.SubPlan)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Test (org.testng.annotations.Test)5 Session (com.facebook.presto.Session)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)3 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)3