Search in sources :

Example 6 with JsonModule

use of com.facebook.airlift.json.JsonModule in project presto by prestodb.

the class DeltaConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new DeltaModule(catalogName, context.getTypeManager()), new HiveS3Module(catalogName), new HiveGcsModule(), new HiveAuthenticationModule(), new HiveMetastoreModule(catalogName, Optional.empty()), binder -> {
            binder.bind(RowExpressionService.class).toInstance(context.getRowExpressionService());
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(DeltaConnector.class);
    } catch (Exception exception) {
        throwIfUnchecked(exception);
        throw new RuntimeException(exception);
    }
}
Also used : HiveS3Module(com.facebook.presto.hive.s3.HiveS3Module) HiveGcsModule(com.facebook.presto.hive.gcs.HiveGcsModule) RowExpressionService(com.facebook.presto.spi.relation.RowExpressionService) Injector(com.google.inject.Injector) HiveAuthenticationModule(com.facebook.presto.hive.authentication.HiveAuthenticationModule) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) HiveMetastoreModule(com.facebook.presto.hive.metastore.HiveMetastoreModule) JsonModule(com.facebook.airlift.json.JsonModule)

Example 7 with JsonModule

use of com.facebook.airlift.json.JsonModule in project presto by prestodb.

the class TestDeltaTableHandle method getJsonCodec.

private JsonCodec<DeltaTableHandle> getJsonCodec() {
    Module module = binder -> {
        binder.install(new JsonModule());
        binder.install(new HandleJsonModule());
        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);
        binder.bind(BlockEncodingSerde.class).to(BlockEncodingManager.class).in(Scopes.SINGLETON);
        newSetBinder(binder, BlockEncoding.class);
        jsonBinder(binder).addSerializerBinding(Block.class).to(BlockJsonSerde.Serializer.class);
        jsonBinder(binder).addDeserializerBinding(Block.class).to(BlockJsonSerde.Deserializer.class);
        jsonCodecBinder(binder).bindJsonCodec(DeltaTableHandle.class);
        jsonCodecBinder(binder).bindJsonCodec(DeltaTable.class);
        jsonCodecBinder(binder).bindJsonCodec(DeltaColumnHandle.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("delta", new DeltaConnectionHandleResolver());
    return injector.getInstance(new Key<JsonCodec<DeltaTableHandle>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) PARTITION(com.facebook.presto.delta.DeltaColumnHandle.ColumnType.PARTITION) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) StandardTypes(com.facebook.presto.common.type.StandardTypes) Key(com.google.inject.Key) BlockEncoding(com.facebook.presto.common.block.BlockEncoding) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) SortedRangeSet(com.facebook.presto.common.predicate.SortedRangeSet) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) REAL(com.facebook.presto.common.type.RealType.REAL) BlockJsonSerde(com.facebook.presto.block.BlockJsonSerde) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) Float.floatToRawIntBits(java.lang.Float.floatToRawIntBits) ImmutableList(com.google.common.collect.ImmutableList) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TypeManager(com.facebook.presto.common.type.TypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) Type(com.facebook.presto.common.type.Type) JsonModule(com.facebook.airlift.json.JsonModule) ImmutableMap(com.google.common.collect.ImmutableMap) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) DATE(com.facebook.presto.common.type.StandardTypes.DATE) Scopes(com.google.inject.Scopes) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) INTEGER(com.facebook.presto.common.type.StandardTypes.INTEGER) Range(com.facebook.presto.common.predicate.Range) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) Injector(com.google.inject.Injector) DOUBLE(com.facebook.presto.common.type.StandardTypes.DOUBLE) List(java.util.List) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Optional(java.util.Optional) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) Block(com.facebook.presto.common.block.Block) HandleResolver(com.facebook.presto.metadata.HandleResolver) REGULAR(com.facebook.presto.delta.DeltaColumnHandle.ColumnType.REGULAR) HandleResolver(com.facebook.presto.metadata.HandleResolver) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) Type(com.facebook.presto.common.type.Type) 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) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) 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) BlockEncoding(com.facebook.presto.common.block.BlockEncoding)

Example 8 with JsonModule

use of com.facebook.airlift.json.JsonModule in project presto by prestodb.

the class TestInformationSchemaTableHandle method startUp.

@BeforeMethod
public void startUp() {
    Injector injector = Guice.createInjector(new JsonModule(), new HandleJsonModule());
    objectMapper = injector.getInstance(ObjectMapper.class);
}
Also used : Injector(com.google.inject.Injector) JsonModule(com.facebook.airlift.json.JsonModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with JsonModule

use of com.facebook.airlift.json.JsonModule 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 10 with JsonModule

use of com.facebook.airlift.json.JsonModule in project presto by prestodb.

the class PrometheusConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "requiredConfig is null");
    try {
        // A plugin is not required to use Guice; it is just very convenient
        Bootstrap app = new Bootstrap(new JsonModule(), new PrometheusModule(context.getTypeManager()));
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(PrometheusConnector.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) JsonModule(com.facebook.airlift.json.JsonModule)

Aggregations

JsonModule (com.facebook.airlift.json.JsonModule)38 Injector (com.google.inject.Injector)37 Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)36 TypeManager (com.facebook.presto.common.type.TypeManager)15 Module (com.google.inject.Module)10 NodeManager (com.facebook.presto.spi.NodeManager)8 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)7 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)7 ImmutableList (com.google.common.collect.ImmutableList)7 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)6 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)6 Type (com.facebook.presto.common.type.Type)6 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)6 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)6 HandleJsonModule (com.facebook.presto.metadata.HandleJsonModule)6 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)6 Multibinder.newSetBinder (com.google.inject.multibindings.Multibinder.newSetBinder)6 Map (java.util.Map)6 Test (org.testng.annotations.Test)6 MBeanModule (org.weakref.jmx.guice.MBeanModule)6