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