Search in sources :

Example 1 with UserAggregator

use of org.neo4j.internal.kernel.api.procs.UserAggregator 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 UserAggregator

use of org.neo4j.internal.kernel.api.procs.UserAggregator 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 UserAggregator

use of org.neo4j.internal.kernel.api.procs.UserAggregator 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)

Example 4 with UserAggregator

use of org.neo4j.internal.kernel.api.procs.UserAggregator in project neo4j by neo4j.

the class UserAggregationFunctionTest method shouldInjectLogging.

@Test
void shouldInjectLogging() throws KernelException {
    // Given
    Log log = spy(Log.class);
    components.register(Log.class, ctx -> log);
    CallableUserAggregationFunction function = procedureCompiler.compileAggregationFunction(LoggingFunction.class).get(0);
    // When
    UserAggregator aggregator = function.create(prepareContext());
    aggregator.update(new AnyValue[] {});
    aggregator.result();
    // Then
    verify(log).debug("1");
    verify(log).info("2");
    verify(log).warn("3");
    verify(log).error("4");
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) Test(org.junit.jupiter.api.Test)

Example 5 with UserAggregator

use of org.neo4j.internal.kernel.api.procs.UserAggregator in project neo4j by neo4j.

the class UserAggregationFunctionTest method shouldRunAggregationFunction.

@Test
void shouldRunAggregationFunction() throws Throwable {
    // Given
    CallableUserAggregationFunction func = compile(SingleAggregationFunction.class).get(0);
    // When
    UserAggregator aggregator = func.create(prepareContext());
    aggregator.update(new AnyValue[] { stringValue("Harry") });
    aggregator.update(new AnyValue[] { stringValue("Bonnie") });
    aggregator.update(new AnyValue[] { stringValue("Sally") });
    aggregator.update(new AnyValue[] { stringValue("Clyde") });
    // Then
    assertThat(aggregator.result()).isEqualTo(VirtualValues.list(stringValue("Bonnie"), stringValue("Clyde")));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) Test(org.junit.jupiter.api.Test)

Aggregations

UserAggregator (org.neo4j.internal.kernel.api.procs.UserAggregator)10 Test (org.junit.jupiter.api.Test)9 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)7 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)4 NTString (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString)1 AccessMode (org.neo4j.internal.kernel.api.security.AccessMode)1 AdminAccessMode (org.neo4j.internal.kernel.api.security.AdminAccessMode)1 SecurityContext (org.neo4j.internal.kernel.api.security.SecurityContext)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 Context (org.neo4j.kernel.api.procedure.Context)1 OverriddenAccessMode (org.neo4j.kernel.impl.api.security.OverriddenAccessMode)1 RestrictedAccessMode (org.neo4j.kernel.impl.api.security.RestrictedAccessMode)1 Log (org.neo4j.logging.Log)1 NullLog (org.neo4j.logging.NullLog)1 MapValue (org.neo4j.values.virtual.MapValue)1