Search in sources :

Example 1 with THRIFT

use of com.facebook.presto.spi.function.FunctionImplementationType.THRIFT in project presto by prestodb.

the class SimpleAddressThriftSqlFunctionExecutionModule method setup.

@Override
protected void setup(Binder binder) {
    ImmutableMap.Builder<Language, SimpleAddressSelectorConfig> thriftConfigBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<Language, ThriftSqlFunctionExecutionConfig> thriftExecutionConfigs = ImmutableMap.builder();
    for (Map.Entry<String, FunctionImplementationType> entry : supportedLanguages.entrySet()) {
        String languageName = entry.getKey();
        Language language = new Language(languageName);
        FunctionImplementationType implementationType = entry.getValue();
        if (implementationType.equals(THRIFT)) {
            thriftConfigBuilder.put(language, buildConfigObject(SimpleAddressSelectorConfig.class, languageName));
            thriftExecutionConfigs.put(language, buildConfigObject(ThriftSqlFunctionExecutionConfig.class, languageName));
        }
    }
    Map<Language, SimpleAddressSelectorConfig> thriftConfigs = thriftConfigBuilder.build();
    if (thriftConfigs.isEmpty()) {
        binder.bind(SqlFunctionExecutor.class).to(NoopSqlFunctionExecutor.class).in(Scopes.SINGLETON);
        return;
    }
    binder.bind(SqlFunctionExecutor.class).to(ThriftSqlFunctionExecutor.class).in(Scopes.SINGLETON);
    driftClientBinder(binder).bindDriftClient(ThriftUdfService.class).withAddressSelector(contextualSimpleAddressSelector(thriftConfigs.entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().getLanguage(), Map.Entry::getValue))));
    binder.bind(new TypeLiteral<Map<Language, ThriftSqlFunctionExecutionConfig>>() {
    }).toInstance(thriftExecutionConfigs.build());
}
Also used : DriftClientBinder.driftClientBinder(com.facebook.drift.client.guice.DriftClientBinder.driftClientBinder) ThriftUdfService(com.facebook.presto.thrift.api.udf.ThriftUdfService) SqlFunctionExecutionModule(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutionModule) SqlFunctionExecutor(com.facebook.presto.spi.function.SqlFunctionExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) Language(com.facebook.presto.spi.function.RoutineCharacteristics.Language) Scopes(com.google.inject.Scopes) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ContextualSimpleAddressSelectorBinder.contextualSimpleAddressSelector(com.facebook.presto.functionNamespace.execution.thrift.ContextualSimpleAddressSelectorBinder.contextualSimpleAddressSelector) Binder(com.google.inject.Binder) Map(java.util.Map) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) TypeLiteral(com.google.inject.TypeLiteral) THRIFT(com.facebook.presto.spi.function.FunctionImplementationType.THRIFT) SimpleAddressSelectorConfig(com.facebook.drift.client.address.SimpleAddressSelectorConfig) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) SimpleAddressSelectorConfig(com.facebook.drift.client.address.SimpleAddressSelectorConfig) ThriftUdfService(com.facebook.presto.thrift.api.udf.ThriftUdfService) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Language(com.facebook.presto.spi.function.RoutineCharacteristics.Language) TypeLiteral(com.google.inject.TypeLiteral) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Example 2 with THRIFT

use of com.facebook.presto.spi.function.FunctionImplementationType.THRIFT in project presto by prestodb.

the class TestPlanRemoteProjections method testRemoteFunctionDisabled.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = ".*Remote functions are not enabled")
public void testRemoteFunctionDisabled() {
    RuleTester tester = new RuleTester(ImmutableList.of());
    FunctionAndTypeManager functionAndTypeManager = tester.getMetadata().getFunctionAndTypeManager();
    functionAndTypeManager.addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL, JAVA, THRIFT), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql,java")));
    functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_1, true);
    tester.assertThat(new PlanRemotePojections(functionAndTypeManager)).on(p -> {
        p.variable("x", INTEGER);
        return p.project(Assignments.builder().put(p.variable("a"), p.rowExpression("unittest.memory.remote_foo(x)")).build(), p.values(p.variable("x", INTEGER)));
    }).matches(anyTree());
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) Parameter(com.facebook.presto.spi.function.Parameter) StandardTypes(com.facebook.presto.common.type.StandardTypes) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) SQL(com.facebook.presto.spi.function.RoutineCharacteristics.Language.SQL) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) Assignments(com.facebook.presto.spi.plan.Assignments) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) PrestoException(com.facebook.presto.spi.PrestoException) ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) THRIFT(com.facebook.presto.spi.function.FunctionImplementationType.THRIFT) RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) BeforeClass(org.testng.annotations.BeforeClass) DETERMINISTIC(com.facebook.presto.spi.function.RoutineCharacteristics.Determinism.DETERMINISTIC) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) DOUBLE(com.facebook.presto.common.type.StandardTypes.DOUBLE) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) List(java.util.List) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) RETURNS_NULL_ON_NULL_INPUT(com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause.RETURNS_NULL_ON_NULL_INPUT) ExpressionMatcher(com.facebook.presto.sql.planner.assertions.ExpressionMatcher) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) FunctionVersion.notVersioned(com.facebook.presto.spi.function.FunctionVersion.notVersioned) CatalogSchemaName(com.facebook.presto.common.CatalogSchemaName) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) Metadata(com.facebook.presto.metadata.Metadata) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) Test(org.testng.annotations.Test)

Aggregations

NoopSqlFunctionExecutor (com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor)2 FunctionImplementationType (com.facebook.presto.spi.function.FunctionImplementationType)2 THRIFT (com.facebook.presto.spi.function.FunctionImplementationType.THRIFT)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 SimpleAddressSelectorConfig (com.facebook.drift.client.address.SimpleAddressSelectorConfig)1 DriftClientBinder.driftClientBinder (com.facebook.drift.client.guice.DriftClientBinder.driftClientBinder)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 CatalogSchemaName (com.facebook.presto.common.CatalogSchemaName)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)1 StandardTypes (com.facebook.presto.common.type.StandardTypes)1 DOUBLE (com.facebook.presto.common.type.StandardTypes.DOUBLE)1 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)1 SqlInvokedFunctionNamespaceManagerConfig (com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig)1 SqlFunctionExecutionModule (com.facebook.presto.functionNamespace.execution.SqlFunctionExecutionModule)1 SqlFunctionExecutors (com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors)1 ContextualSimpleAddressSelectorBinder.contextualSimpleAddressSelector (com.facebook.presto.functionNamespace.execution.thrift.ContextualSimpleAddressSelectorBinder.contextualSimpleAddressSelector)1 InMemoryFunctionNamespaceManager (com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager)1 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)1