Search in sources :

Example 1 with InMemoryFunctionNamespaceManager

use of com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager 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 InMemoryFunctionNamespaceManager

use of com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager 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 InMemoryFunctionNamespaceManager

use of com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager in project presto by prestodb.

the class TestSqlInvokedFunctionNamespaceManager method testCaching.

@Test
public void testCaching() {
    InMemoryFunctionNamespaceManager functionNamespaceManager = createFunctionNamespaceManager();
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    // fetchFunctionsDirect does not produce the same function reference
    SqlInvokedFunction function1 = getOnlyElement(functionNamespaceManager.fetchFunctionsDirect(POWER_TOWER));
    SqlInvokedFunction function2 = getOnlyElement(functionNamespaceManager.fetchFunctionsDirect(POWER_TOWER));
    assertEquals(function1, function2);
    assertNotSame(function1, function2);
    // fetchFunctionMetadataDirect does not produce the same metadata reference
    FunctionMetadata metadata1 = functionNamespaceManager.fetchFunctionMetadataDirect(function1.getRequiredFunctionHandle());
    FunctionMetadata metadata2 = functionNamespaceManager.fetchFunctionMetadataDirect(function2.getRequiredFunctionHandle());
    assertEquals(metadata1, metadata2);
    assertNotSame(metadata1, metadata2);
    // getFunctionMetadata produces the same metadata reference
    metadata1 = functionNamespaceManager.getFunctionMetadata(function1.getRequiredFunctionHandle());
    metadata2 = functionNamespaceManager.getFunctionMetadata(function2.getRequiredFunctionHandle());
    assertSame(metadata1, metadata2);
    // getFunctions produces the same function collection reference
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_INT, false);
    FunctionNamespaceTransactionHandle transaction1 = functionNamespaceManager.beginTransaction();
    FunctionNamespaceTransactionHandle transaction2 = functionNamespaceManager.beginTransaction();
    Collection<SqlInvokedFunction> functions1 = functionNamespaceManager.getFunctions(Optional.of(transaction1), POWER_TOWER);
    Collection<SqlInvokedFunction> functions2 = functionNamespaceManager.getFunctions(Optional.of(transaction2), POWER_TOWER);
    assertEquals(functions1.size(), 2);
    assertSame(functions1, functions2);
}
Also used : FunctionNamespaceTransactionHandle(com.facebook.presto.spi.function.FunctionNamespaceTransactionHandle) FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) Test(org.testng.annotations.Test)

Example 4 with InMemoryFunctionNamespaceManager

use of com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager in project presto by prestodb.

the class TestSqlInvokedFunctionNamespaceManager method testCreateFunctionFailed.

@Test
public void testCreateFunctionFailed() {
    InMemoryFunctionNamespaceManager functionNamespaceManager = createFunctionNamespaceManager();
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    assertPrestoException(() -> functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE_UPDATED, false), GENERIC_USER_ERROR, ".*Function 'unittest.memory.power_tower\\(double\\)' already exists");
}
Also used : InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) Test(org.testng.annotations.Test)

Example 5 with InMemoryFunctionNamespaceManager

use of com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager in project presto by prestodb.

the class TestSqlInvokedFunctionNamespaceManager method testCreateFunction.

@Test
public void testCreateFunction() {
    InMemoryFunctionNamespaceManager functionNamespaceManager = createFunctionNamespaceManager();
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    assertEquals(functionNamespaceManager.listFunctions(Optional.empty(), Optional.empty()), ImmutableSet.of(FUNCTION_POWER_TOWER_DOUBLE.withVersion("1")));
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_INT, false);
    assertEquals(ImmutableSet.copyOf(functionNamespaceManager.listFunctions(Optional.empty(), Optional.empty())), ImmutableSet.of(FUNCTION_POWER_TOWER_DOUBLE.withVersion("1"), FUNCTION_POWER_TOWER_INT.withVersion("1")));
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE_UPDATED, true);
    assertEquals(ImmutableSet.copyOf(functionNamespaceManager.listFunctions(Optional.empty(), Optional.empty())), ImmutableSet.of(FUNCTION_POWER_TOWER_DOUBLE_UPDATED.withVersion("2"), FUNCTION_POWER_TOWER_INT.withVersion("1")));
}
Also used : InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) Test(org.testng.annotations.Test)

Aggregations

InMemoryFunctionNamespaceManager (com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager)9 NoopSqlFunctionExecutor (com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor)6 SqlFunctionExecutors (com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors)6 SqlInvokedFunctionNamespaceManagerConfig (com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig)5 Test (org.testng.annotations.Test)5 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)4 BeforeClass (org.testng.annotations.BeforeClass)4 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)3 RuleTester (com.facebook.presto.sql.planner.iterative.rule.test.RuleTester)3 FunctionNamespaceTransactionHandle (com.facebook.presto.spi.function.FunctionNamespaceTransactionHandle)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