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);
}
Aggregations