Search in sources :

Example 1 with CallableUserAggregationFunction

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

the class ProcedureCompilationTest method shouldCallAggregationFunction.

@Test
void shouldCallAggregationFunction() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTInteger).out(NTInteger).build();
    // When
    CallableUserAggregationFunction adder = compileAggregation(signature, emptyList(), method("createAdder"), method(Adder.class, "update", long.class), method(Adder.class, "result"));
    // Then
    UserAggregator aggregator = adder.create(ctx);
    for (int i = 1; i <= 10; i++) {
        aggregator.update(new AnyValue[] { longValue(i) });
    }
    assertEquals(longValue(55), aggregator.result());
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 2 with CallableUserAggregationFunction

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

the class ProcedureCompilationTest method shouldCallAggregationFunctionWithObject.

@Test
void shouldCallAggregationFunctionWithObject() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTAny).out(NTAny).build();
    // When
    CallableUserAggregationFunction first = compileAggregation(signature, emptyList(), method("first"), method(First.class, "update", Object.class), method(First.class, "result"));
    // Then
    UserAggregator aggregator = first.create(ctx);
    aggregator.update(new AnyValue[] { longValue(3) });
    aggregator.update(new AnyValue[] { longValue(4) });
    aggregator.update(new AnyValue[] { longValue(5) });
    assertEquals(longValue(3), aggregator.result());
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 3 with CallableUserAggregationFunction

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

the class ProcedureCompilationTest method shouldExposeUserFunctionSignatureOnAggregations.

@Test
void shouldExposeUserFunctionSignatureOnAggregations() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTInteger).out(NTInteger).build();
    // When
    CallableUserAggregationFunction adder = compileAggregation(signature, emptyList(), method("createAdder"), method(Adder.class, "update", long.class), method(Adder.class, "result"));
    // Then
    assertEquals(adder.signature(), signature);
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 4 with CallableUserAggregationFunction

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

the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeAggregationFunction.

@Test
void shouldFailNicelyWhenUnsafeAPISafeModeAggregationFunction() throws Throwable {
    // When
    List<CallableUserAggregationFunction> procList = compiler.compileAggregationFunction(AggregationFunctionWithUnsafeAPI.class);
    assertThat(logProvider).forClass(getClass()).forLevel(WARN).containsMessages("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
    assertThat(procList.size()).isEqualTo(1);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> {
        procList.get(0).create(prepareContext()).update(new AnyValue[] {});
        procList.get(0).create(prepareContext()).result();
    });
    assertThat(exception.getMessage()).contains("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 5 with CallableUserAggregationFunction

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

the class UserAggregationFunctionTest method shouldRunAggregationFunctionWithInternalTypes.

@Test
void shouldRunAggregationFunctionWithInternalTypes() throws Throwable {
    // Given
    CallableUserAggregationFunction func = compile(InternalTypes.class).get(0);
    // When
    UserAggregator aggregator = func.create(prepareContext());
    aggregator.update(new AnyValue[] { longValue(1) });
    aggregator.update(new AnyValue[] { longValue(1) });
    aggregator.update(new AnyValue[] { longValue(1) });
    aggregator.update(new AnyValue[] { longValue(1) });
    aggregator.update(new AnyValue[] { longValue(1) });
    // Then
    assertThat(aggregator.result()).isEqualTo(longValue(5));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) Test(org.junit.jupiter.api.Test)

Aggregations

CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)20 Test (org.junit.jupiter.api.Test)15 UserAggregator (org.neo4j.internal.kernel.api.procs.UserAggregator)7 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)7 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)6 Log (org.neo4j.logging.Log)5 NullLog (org.neo4j.logging.NullLog)4 Method (java.lang.reflect.Method)2 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)2 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)2 FailedLoadAggregatedFunction (org.neo4j.kernel.api.procedure.FailedLoadAggregatedFunction)2 UserAggregationFunction (org.neo4j.procedure.UserAggregationFunction)2 UserAggregationResult (org.neo4j.procedure.UserAggregationResult)2 UserAggregationUpdate (org.neo4j.procedure.UserAggregationUpdate)2 AnyValue (org.neo4j.values.AnyValue)2 Constructor (java.lang.reflect.Constructor)1 Modifier.isPublic (java.lang.reflect.Modifier.isPublic)1