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