use of io.hetu.core.plugin.functionnamespace.memory.InMemoryFunctionNamespaceManager in project hetu-core by openlookeng.
the class FunctionNamespaceTestCommon method testGetFunction.
/**
* test get function
*/
public void testGetFunction(AbstractSqlInvokedFunctionNamespaceManager functionNamespaceManager) {
QualifiedObjectName powerTower = QualifiedObjectName.valueOf(new CatalogSchemaName(this.catalogName, funcNsSchemaName), functionName);
List<Parameter> parameters = ImmutableList.of(new Parameter("x", parseTypeSignature(DOUBLE)));
List<Parameter> parameters1 = ImmutableList.of(new Parameter("y", parseTypeSignature(INTEGER)), new Parameter("x", parseTypeSignature(DOUBLE)));
String funcDesc = "power tower test";
String funcBody = "RETURN pow(x, x)";
Map<String, String> funcProperties = ImmutableMap.of("executor", "mysql");
SqlInvokedFunction function = new SqlInvokedFunction(powerTower, parameters, parseTypeSignature(DOUBLE), funcDesc, RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).setLanguage(JDBC).build(), funcBody, funcProperties, Optional.empty());
SqlInvokedFunction function1 = new SqlInvokedFunction(powerTower, parameters1, parseTypeSignature(DOUBLE), funcDesc, RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).setLanguage(JDBC).build(), funcBody, funcProperties, Optional.empty());
try {
functionNamespaceManager.createFunction(function, false);
functionNamespaceManager.createFunction(function1, false);
} catch (PrestoException e) {
fail(format("Create function(id=%s) failed.", function.getFunctionId().toString()));
}
if ((functionNamespaceManager instanceof InMemoryFunctionNamespaceManager)) {
// trans to InMemoryFunctionNamespaceManager obj for sub classes method test
InMemoryFunctionNamespaceManager manager = (InMemoryFunctionNamespaceManager) functionNamespaceManager;
List<SqlInvokedFunction> storedFunc = manager.listFunctions();
assertTrue(storedFunc.size() == 2);
storedFunc = manager.fetchFunctionsDirect(powerTower);
assertTrue(storedFunc.size() == 2);
Optional<SqlInvokedFunction> singleFunc = manager.fetchFunctionsDirect(powerTower, parameters.stream().map(x -> x.getType()).collect(Collectors.toList()));
assertTrue(singleFunc.isPresent());
FunctionMetadata funcMeta = manager.fetchFunctionMetadataDirect(singleFunc.get().getFunctionHandle().get());
assertEquals(funcMeta.getName(), powerTower);
}
}
Aggregations