Search in sources :

Example 1 with TestingHandleResolver

use of com.facebook.presto.testing.TestingHandleResolver in project presto by prestodb.

the class TestStatisticsWriterNode method getJsonCodec.

private JsonCodec<StatisticsWriterNode> getJsonCodec() throws Exception {
    Module module = binder -> {
        SqlParser sqlParser = new SqlParser();
        FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
        binder.install(new JsonModule());
        binder.install(new HandleJsonModule());
        binder.bind(SqlParser.class).toInstance(sqlParser);
        binder.bind(TypeManager.class).toInstance(functionAndTypeManager);
        newSetBinder(binder, Type.class);
        jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
        jsonCodecBinder(binder).bindJsonCodec(StatisticsWriterNode.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("test", new TestingHandleResolver());
    return injector.getInstance(new Key<JsonCodec<StatisticsWriterNode>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) ColumnStatisticMetadata(com.facebook.presto.spi.statistics.ColumnStatisticMetadata) Key(com.google.inject.Key) Assert.assertEquals(org.testng.Assert.assertEquals) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) ImmutableList(com.google.common.collect.ImmutableList) TypeManager(com.facebook.presto.common.type.TypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) TableHandle(com.facebook.presto.spi.TableHandle) Type(com.facebook.presto.common.type.Type) JsonModule(com.facebook.airlift.json.JsonModule) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ROW_COUNT(com.facebook.presto.spi.statistics.TableStatisticType.ROW_COUNT) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) UUID(java.util.UUID) SqlParser(com.facebook.presto.sql.parser.SqlParser) Injector(com.google.inject.Injector) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) HandleResolver(com.facebook.presto.metadata.HandleResolver) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) HandleResolver(com.facebook.presto.metadata.HandleResolver) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) SqlParser(com.facebook.presto.sql.parser.SqlParser) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) Type(com.facebook.presto.common.type.Type) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) JsonCodec(com.facebook.airlift.json.JsonCodec) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Module(com.google.inject.Module) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) TypeDeserializer(com.facebook.presto.type.TypeDeserializer)

Example 2 with TestingHandleResolver

use of com.facebook.presto.testing.TestingHandleResolver 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)

Aggregations

Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)2 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)2 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)2 JsonModule (com.facebook.airlift.json.JsonModule)2 Type (com.facebook.presto.common.type.Type)2 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)2 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)2 HandleJsonModule (com.facebook.presto.metadata.HandleJsonModule)2 HandleResolver (com.facebook.presto.metadata.HandleResolver)2 TestingHandleResolver (com.facebook.presto.testing.TestingHandleResolver)2 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)2 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2 Multibinder.newSetBinder (com.google.inject.multibindings.Multibinder.newSetBinder)2 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)1 TestingHttpClient (com.facebook.airlift.http.client.testing.TestingHttpClient)1 JsonMapper (com.facebook.airlift.jaxrs.JsonMapper)1 JaxrsTestingHttpProcessor (com.facebook.airlift.jaxrs.testing.JaxrsTestingHttpProcessor)1 ThriftMapper (com.facebook.airlift.jaxrs.thrift.ThriftMapper)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1