Search in sources :

Example 1 with SqlInvokedFunctionNamespaceManagerConfig

use of com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig in project presto by prestodb.

the class TestInlineSqlFunctions method setup.

@BeforeTest
public void setup() {
    RuleTester tester = new RuleTester();
    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(SQL_FUNCTION_SQUARE, true);
    functionAndTypeManager.createFunction(THRIFT_FUNCTION_FOO, true);
    functionAndTypeManager.createFunction(SQL_FUNCTION_ADD_1_TO_INT_ARRAY, true);
    functionAndTypeManager.createFunction(SQL_FUNCTION_ADD_1_TO_BIGINT_ARRAY, true);
    this.tester = tester;
}
Also used : 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) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with SqlInvokedFunctionNamespaceManagerConfig

use of com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig in project presto by prestodb.

the class TestRewriteFilterWithExternalFunctionToProject method setup.

@BeforeClass
public void setup() {
    FunctionAndTypeManager functionAndTypeManager = getFunctionManager();
    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_TANGENT, true);
    functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO, true);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with SqlInvokedFunctionNamespaceManagerConfig

use of com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig in project presto by prestodb.

the class SimpleAddressSqlFunctionExecutorsModule method setup.

@Override
protected void setup(Binder binder) {
    SqlInvokedFunctionNamespaceManagerConfig config = buildConfigObject(SqlInvokedFunctionNamespaceManagerConfig.class);
    ImmutableMap.Builder<Language, FunctionImplementationType> languageImplementationTypeMap = ImmutableMap.builder();
    ImmutableMap.Builder<String, FunctionImplementationType> supportedLanguages = ImmutableMap.builder();
    for (String languageName : config.getSupportedFunctionLanguages()) {
        Language language = new Language(languageName);
        FunctionImplementationType implementationType = buildConfigObject(SqlFunctionLanguageConfig.class, languageName).getFunctionImplementationType();
        languageImplementationTypeMap.put(language, implementationType);
        supportedLanguages.put(languageName, implementationType);
    }
    // for SqlFunctionExecutor
    sqlFunctionExecutorModule.setSupportedLanguages(supportedLanguages.build());
    install(sqlFunctionExecutorModule);
    // for SqlFunctionExecutors
    binder.bind(SqlFunctionExecutors.class).in(SINGLETON);
    binder.bind(new TypeLiteral<Map<Language, FunctionImplementationType>>() {
    }).toInstance(languageImplementationTypeMap.build());
}
Also used : Language(com.facebook.presto.spi.function.RoutineCharacteristics.Language) TypeLiteral(com.google.inject.TypeLiteral) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with SqlInvokedFunctionNamespaceManagerConfig

use of com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig in project presto by prestodb.

the class AbstractAnalyzerTest method setup.

@BeforeClass
public void setup() {
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    accessControl = new AccessControlManager(transactionManager);
    metadata = createTestMetadataManager(transactionManager, new FeaturesConfig());
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(ImmutableList.of(APPLY_FUNCTION));
    metadata.getFunctionAndTypeManager().addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql")));
    metadata.getFunctionAndTypeManager().createFunction(SQL_FUNCTION_SQUARE, true);
    Catalog tpchTestCatalog = createTestingCatalog(TPCH_CATALOG, TPCH_CONNECTOR_ID);
    catalogManager.registerCatalog(tpchTestCatalog);
    metadata.getAnalyzePropertyManager().addProperties(TPCH_CONNECTOR_ID, tpchTestCatalog.getConnector(TPCH_CONNECTOR_ID).getAnalyzeProperties());
    catalogManager.registerCatalog(createTestingCatalog(SECOND_CATALOG, SECOND_CONNECTOR_ID));
    catalogManager.registerCatalog(createTestingCatalog(THIRD_CATALOG, THIRD_CONNECTOR_ID));
    SchemaTableName table1 = new SchemaTableName("s1", "t1");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table1, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT))), false));
    SchemaTableName table2 = new SchemaTableName("s1", "t2");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table2, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT))), false));
    SchemaTableName table3 = new SchemaTableName("s1", "t3");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table3, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("x", BIGINT, null, true))), false));
    // table in different catalog
    SchemaTableName table4 = new SchemaTableName("s2", "t4");
    inSetupTransaction(session -> metadata.createTable(session, SECOND_CATALOG, new ConnectorTableMetadata(table4, ImmutableList.of(new ColumnMetadata("a", BIGINT))), false));
    // table with a hidden column
    SchemaTableName table5 = new SchemaTableName("s1", "t5");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table5, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT, null, true))), false));
    // table with a varchar column
    SchemaTableName table6 = new SchemaTableName("s1", "t6");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table6, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", VARCHAR), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT))), false));
    // table with bigint, double, array of bigints and array of doubles column
    SchemaTableName table7 = new SchemaTableName("s1", "t7");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table7, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", DOUBLE), new ColumnMetadata("c", new ArrayType(BIGINT)), new ColumnMetadata("d", new ArrayType(DOUBLE)))), false));
    // table with double, array of bigints, real, and bigint
    SchemaTableName table8 = new SchemaTableName("s1", "t8");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table8, ImmutableList.of(new ColumnMetadata("a", DOUBLE), new ColumnMetadata("b", new ArrayType(BIGINT)), new ColumnMetadata("c", RealType.REAL), new ColumnMetadata("d", BIGINT))), false));
    // table with double, array of bigints, real, and bigint
    SchemaTableName table9 = new SchemaTableName("s1", "t9");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table9, ImmutableList.of(new ColumnMetadata("a", DOUBLE), new ColumnMetadata("b", new ArrayType(BIGINT)), new ColumnMetadata("c", RealType.REAL), new ColumnMetadata("d", BIGINT))), false));
    // table with nested struct
    SchemaTableName table10 = new SchemaTableName("s1", "t10");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table10, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", RowType.from(ImmutableList.of(new RowType.Field(Optional.of("w"), BIGINT), new RowType.Field(Optional.of("x"), RowType.from(ImmutableList.of(new RowType.Field(Optional.of("y"), BIGINT), new RowType.Field(Optional.of("z"), DOUBLE))))))), new ColumnMetadata("c", RowType.from(ImmutableList.of(new RowType.Field(Optional.of("d"), BIGINT)))))), false));
    // valid view referencing table in same schema
    String viewData1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata1 = new ConnectorTableMetadata(new SchemaTableName("s1", "v1"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata1, viewData1, false));
    // stale view (different column type)
    String viewData2 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", VARCHAR)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata2 = new ConnectorTableMetadata(new SchemaTableName("s1", "v2"), ImmutableList.of(new ColumnMetadata("a", VARCHAR)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata2, viewData2, false));
    // view referencing table in different schema from itself and session
    String viewData3 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t4", Optional.of(SECOND_CATALOG), Optional.of("s2"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("owner"), false));
    ConnectorTableMetadata viewMetadata3 = new ConnectorTableMetadata(new SchemaTableName("s3", "v3"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, THIRD_CATALOG, viewMetadata3, viewData3, false));
    // valid view with uppercase column name
    String viewData4 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select A from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata4 = new ConnectorTableMetadata(new SchemaTableName("s1", "v4"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata4, viewData4, false));
    // recursive view referencing to itself
    String viewData5 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select * from v5", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata5 = new ConnectorTableMetadata(new SchemaTableName("s1", "v5"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata5, viewData5, false));
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) RowType(com.facebook.presto.common.type.RowType) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) SchemaTableName(com.facebook.presto.spi.SchemaTableName) CatalogManager(com.facebook.presto.metadata.CatalogManager) Catalog(com.facebook.presto.metadata.Catalog) ArrayType(com.facebook.presto.common.type.ArrayType) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with SqlInvokedFunctionNamespaceManagerConfig

use of com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig in project presto by prestodb.

the class TestPlanRemoteProjections method setup.

@BeforeClass
public void setup() {
    tester = new RuleTester(ImmutableList.of(), ImmutableMap.of("remote_functions_enabled", "true"));
    FunctionAndTypeManager functionAndTypeManager = 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_0, true);
    functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_1, true);
    functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_2, true);
    functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO_3, true);
}
Also used : 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) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

SqlInvokedFunctionNamespaceManagerConfig (com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig)6 NoopSqlFunctionExecutor (com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor)5 SqlFunctionExecutors (com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors)5 InMemoryFunctionNamespaceManager (com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager)5 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)4 BeforeClass (org.testng.annotations.BeforeClass)4 RuleTester (com.facebook.presto.sql.planner.iterative.rule.test.RuleTester)3 FunctionImplementationType (com.facebook.presto.spi.function.FunctionImplementationType)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 CatalogSchemaName (com.facebook.presto.common.CatalogSchemaName)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)1 RowType (com.facebook.presto.common.type.RowType)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 Catalog (com.facebook.presto.metadata.Catalog)1 CatalogManager (com.facebook.presto.metadata.CatalogManager)1