Search in sources :

Example 6 with SqlFunctionExecutors

use of com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors 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)

Aggregations

NoopSqlFunctionExecutor (com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor)6 SqlFunctionExecutors (com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors)6 InMemoryFunctionNamespaceManager (com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager)6 SqlInvokedFunctionNamespaceManagerConfig (com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig)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 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)2 Test (org.testng.annotations.Test)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