Search in sources :

Example 1 with CallableUserAggregationFunction

use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.

the class Procedures method start.

@Override
public void start() throws Throwable {
    ProcedureJarLoader loader = new ProcedureJarLoader(compiler, log);
    ProcedureJarLoader.Callables callables = loader.loadProceduresFromDir(pluginDir);
    for (CallableProcedure procedure : callables.procedures()) {
        register(procedure);
    }
    for (CallableUserFunction function : callables.functions()) {
        register(function);
    }
    for (CallableUserAggregationFunction function : callables.aggregationFunctions()) {
        register(function);
    }
    // And register built-in procedures
    builtin.accept(this);
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure)

Example 2 with CallableUserAggregationFunction

use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.

the class ResourceInjectionTest method shouldCompileAndRunUserAggregationFunctions.

@Test
public void shouldCompileAndRunUserAggregationFunctions() throws Throwable {
    // Given
    CallableUserAggregationFunction proc = compiler.compileAggregationFunction(AggregationFunctionWithInjectedAPI.class).get(0);
    // When
    proc.create(new BasicContext()).update(new Object[] {});
    Object out = proc.create(new BasicContext()).result();
    // Then
    assertThat(out, equalTo("[Bonnie, Clyde]"));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 3 with CallableUserAggregationFunction

use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.

the class ReflectiveUserAggregationFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.

@Test
public void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
    // Given
    List<CallableUserAggregationFunction> compiled = compile(MultiFunction.class);
    CallableUserAggregationFunction f1 = compiled.get(0);
    CallableUserAggregationFunction f2 = compiled.get(1);
    // When
    CallableUserAggregationFunction.Aggregator f1Aggregator = f1.create(new BasicContext());
    f1Aggregator.update(new Object[] { "Bonnie" });
    f1Aggregator.update(new Object[] { "Clyde" });
    CallableUserAggregationFunction.Aggregator f2Aggregator = f2.create(new BasicContext());
    f2Aggregator.update(new Object[] { "Bonnie", 1337L });
    f2Aggregator.update(new Object[] { "Bonnie", 42L });
    // Then
    assertThat(f1Aggregator.result(), equalTo(Arrays.asList("Bonnie", "Clyde")));
    assertThat(((Map) f2Aggregator.result()).get("Bonnie"), equalTo(1337L));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 4 with CallableUserAggregationFunction

use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.

the class ReflectiveUserAggregationFunctionTest method shouldSupportFunctionDeprecation.

@Test
public void shouldSupportFunctionDeprecation() throws Throwable {
    // Given
    Log log = mock(Log.class);
    ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
    // When
    List<CallableUserAggregationFunction> funcs = procedureCompiler.compileAggregationFunction(FunctionWithDeprecation.class);
    // Then
    verify(log).warn("Use of @UserAggregationFunction(deprecatedBy) without @Deprecated in org.neo4j.kernel.impl.proc.badFunc");
    verifyNoMoreInteractions(log);
    for (CallableUserAggregationFunction func : funcs) {
        String name = func.signature().name().name();
        func.create(new BasicContext());
        switch(name) {
            case "newFunc":
                assertFalse("Should not be deprecated", func.signature().deprecated().isPresent());
                break;
            case "oldFunc":
            case "badFunc":
                assertTrue("Should be deprecated", func.signature().deprecated().isPresent());
                assertThat(func.signature().deprecated().get(), equalTo("newFunc"));
                break;
            default:
                fail("Unexpected function: " + name);
        }
    }
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 5 with CallableUserAggregationFunction

use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.

the class ReflectiveUserAggregationFunctionTest method shouldRunAggregationFunction.

@Test
public void shouldRunAggregationFunction() throws Throwable {
    // Given
    CallableUserAggregationFunction func = compile(SingleAggregationFunction.class).get(0);
    // When
    CallableUserAggregationFunction.Aggregator aggregator = func.create(new BasicContext());
    aggregator.update(new Object[] { "Harry" });
    aggregator.update(new Object[] { "Bonnie" });
    aggregator.update(new Object[] { "Sally" });
    aggregator.update(new Object[] { "Clyde" });
    // Then
    assertThat(aggregator.result(), equalTo(Arrays.asList("Bonnie", "Clyde")));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Aggregations

CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)13 Test (org.junit.Test)10 BasicContext (org.neo4j.kernel.api.proc.BasicContext)7 Log (org.neo4j.logging.Log)5 NullLog (org.neo4j.logging.NullLog)4 MethodHandle (java.lang.invoke.MethodHandle)2 Method (java.lang.reflect.Method)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)2 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)2 FailedLoadAggregatedFunction (org.neo4j.kernel.api.proc.FailedLoadAggregatedFunction)2 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)2 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)2 UserAggregationFunction (org.neo4j.procedure.UserAggregationFunction)2 UserAggregationResult (org.neo4j.procedure.UserAggregationResult)2 UserAggregationUpdate (org.neo4j.procedure.UserAggregationUpdate)2 MethodHandles (java.lang.invoke.MethodHandles)1 Modifier (java.lang.reflect.Modifier)1 ArrayList (java.util.ArrayList)1