Search in sources :

Example 21 with SqlInvokedFunction

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

the class TestSqlInvokedFunctionNamespaceManager method testTransactionalGetFunction.

@Test
public void testTransactionalGetFunction() {
    InMemoryFunctionNamespaceManager functionNamespaceManager = new InMemoryFunctionNamespaceManager(TEST_CATALOG, new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setFunctionCacheExpiration(new Duration(0, MILLISECONDS)).setFunctionInstanceCacheExpiration(new Duration(0, MILLISECONDS)));
    // begin first transaction
    FunctionNamespaceTransactionHandle transaction1 = functionNamespaceManager.beginTransaction();
    assertEquals(functionNamespaceManager.getFunctions(Optional.of(transaction1), POWER_TOWER).size(), 0);
    // create function, first transaction still sees no functions
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    assertEquals(functionNamespaceManager.getFunctions(Optional.of(transaction1), POWER_TOWER).size(), 0);
    // second transaction sees newly created function
    FunctionNamespaceTransactionHandle transaction2 = functionNamespaceManager.beginTransaction();
    Collection<SqlInvokedFunction> functions2 = functionNamespaceManager.getFunctions(Optional.of(transaction2), POWER_TOWER);
    assertEquals(functions2.size(), 1);
    assertEquals(getOnlyElement(functions2), FUNCTION_POWER_TOWER_DOUBLE.withVersion("1"));
    // update the function, second transaction still sees the old functions
    functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE_UPDATED, true);
    functions2 = functionNamespaceManager.getFunctions(Optional.of(transaction2), POWER_TOWER);
    assertEquals(functions2.size(), 1);
    assertEquals(getOnlyElement(functions2), FUNCTION_POWER_TOWER_DOUBLE.withVersion("1"));
    // third transaction sees the updated function
    FunctionNamespaceTransactionHandle transaction3 = functionNamespaceManager.beginTransaction();
    Collection<SqlInvokedFunction> functions3 = functionNamespaceManager.getFunctions(Optional.of(transaction3), POWER_TOWER);
    assertEquals(functions3.size(), 1);
    assertEquals(getOnlyElement(functions3), FUNCTION_POWER_TOWER_DOUBLE_UPDATED.withVersion("2"));
    functionNamespaceManager.commit(transaction1);
    functionNamespaceManager.commit(transaction2);
    functionNamespaceManager.commit(transaction3);
}
Also used : FunctionNamespaceTransactionHandle(com.facebook.presto.spi.function.FunctionNamespaceTransactionHandle) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) Duration(io.airlift.units.Duration) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) Test(org.testng.annotations.Test)

Example 22 with SqlInvokedFunction

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

the class TestMySqlFunctionNamespaceManager method testListFunction.

@Test
public void testListFunction() {
    createFunctionNamespace(TEST_CATALOG, "schema1");
    createFunctionNamespace(TEST_CATALOG, "schema2");
    SqlInvokedFunction function1 = constructTestFunction(QualifiedObjectName.valueOf(TEST_CATALOG, "schema1", "power_tower"));
    SqlInvokedFunction function2 = constructTestFunction(QualifiedObjectName.valueOf(TEST_CATALOG, "schema2", "power_tower"));
    createFunction(function1, false);
    createFunction(function2, false);
    assertListFunctions(function1.withVersion("1"), function2.withVersion("1"));
    assertListFunctions(Optional.of(format("%s.%%", TEST_CATALOG)), Optional.empty(), function1.withVersion("1"), function2.withVersion("1"));
    assertListFunctions(Optional.of(format("%s.%s.%%", TEST_CATALOG, "schema1")), Optional.empty(), function1.withVersion("1"));
    assertListFunctions(Optional.of("%schema%"), Optional.empty(), function1.withVersion("1"), function2.withVersion("1"));
    assertListFunctions(Optional.of("%power$_tower"), Optional.of("$"), function1.withVersion("1"), function2.withVersion("1"));
}
Also used : SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) Test(org.testng.annotations.Test)

Aggregations

SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)22 SqlFunctionId (com.facebook.presto.spi.function.SqlFunctionId)12 PrestoException (com.facebook.presto.spi.PrestoException)10 List (java.util.List)8 Map (java.util.Map)8 Parameter (com.facebook.presto.spi.function.Parameter)7 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 Optional (java.util.Optional)7 PRIVATE (com.facebook.presto.bytecode.Access.PRIVATE)4 PUBLIC (com.facebook.presto.bytecode.Access.PUBLIC)4 Access.a (com.facebook.presto.bytecode.Access.a)4 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)4 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)4 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)4 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)4 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)4 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)4 Parameter (com.facebook.presto.bytecode.Parameter)4 Parameter.arg (com.facebook.presto.bytecode.Parameter.arg)4