Search in sources :

Example 1 with InMemoryFunctionNamespaceManager

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);
    }
}
Also used : FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) Parameter(io.prestosql.spi.function.Parameter) PrestoException(io.prestosql.spi.PrestoException) InMemoryFunctionNamespaceManager(io.hetu.core.plugin.functionnamespace.memory.InMemoryFunctionNamespaceManager) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName)

Aggregations

InMemoryFunctionNamespaceManager (io.hetu.core.plugin.functionnamespace.memory.InMemoryFunctionNamespaceManager)1 PrestoException (io.prestosql.spi.PrestoException)1 CatalogSchemaName (io.prestosql.spi.connector.CatalogSchemaName)1 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)1 FunctionMetadata (io.prestosql.spi.function.FunctionMetadata)1 Parameter (io.prestosql.spi.function.Parameter)1 SqlInvokedFunction (io.prestosql.spi.function.SqlInvokedFunction)1