Search in sources :

Example 1 with UserFunctionSignature

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

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

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

the class ProcedureCompilationTest method shouldCallSimpleMethod.

@Test
void shouldCallSimpleMethod() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").out(NTInteger).build();
    // When
    CallableUserFunction longMethod = compileFunction(signature, emptyList(), method("longMethod"));
    // Then
    assertEquals(longMethod.apply(ctx, EMPTY), longValue(1337L));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 4 with UserFunctionSignature

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

the class ProcedureCompilationTest method shouldCallMethodWithCompositeParameters.

@Test
void shouldCallMethodWithCompositeParameters() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("l", NTList(NTAny)).out(NTString).build();
    // When
    CallableUserFunction concatMethod = compileFunction(signature, emptyList(), method("concat", List.class));
    // Then
    assertEquals(stringValue("421.1true"), concatMethod.apply(ctx, new AnyValue[] { list(longValue(42), doubleValue(1.1), TRUE) }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 5 with UserFunctionSignature

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

the class ProcedureCompilationTest method shouldHandleThrowingUDF.

@Test
void shouldHandleThrowingUDF() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").out(NTInteger).build();
    // When
    CallableUserFunction longMethod = compileFunction(signature, emptyList(), method("throwingLongMethod"));
    // Then
    assertThrows(ProcedureException.class, () -> longMethod.apply(ctx, EMPTY));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Aggregations

UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)22 Test (org.junit.jupiter.api.Test)16 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)13 AnyValue (org.neo4j.values.AnyValue)7 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)6 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 UserAggregator (org.neo4j.internal.kernel.api.procs.UserAggregator)4 Method (java.lang.reflect.Method)3 NTString (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString)3 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 ClassGenerator (org.neo4j.codegen.ClassGenerator)2 ClassHandle (org.neo4j.codegen.ClassHandle)2 CodeBlock (org.neo4j.codegen.CodeBlock)2 CodeGenerator (org.neo4j.codegen.CodeGenerator)2 FieldReference (org.neo4j.codegen.FieldReference)2 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 NTList (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList)2