Search in sources :

Example 1 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction 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 2 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction 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 3 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction 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)

Example 4 with CallableUserFunction

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

the class ProcedureCompilationTest method shouldHandleByteArrays.

@Test
void shouldHandleByteArrays() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("bytes", NTByteArray).out(NTByteArray).build();
    // When
    CallableUserFunction bytesMethod = compileFunction(signature, emptyList(), method("testMethod", byte[].class));
    // Then
    assertEquals(byteArray(new byte[] { 1, 2, 3 }), bytesMethod.apply(ctx, new AnyValue[] { byteArray(new byte[] { 1, 2, 3 }) }));
    assertEquals(byteArray(new byte[] { 1, 2, 3 }), bytesMethod.apply(ctx, new AnyValue[] { list(byteValue((byte) 1), byteValue((byte) 2), byteValue((byte) 3)) }));
    assertEquals(NO_VALUE, bytesMethod.apply(ctx, new AnyValue[] { NO_VALUE }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 5 with CallableUserFunction

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

the class ProcedureCompilationTest method shouldCallMethodWithParameters.

@Test
void shouldCallMethodWithParameters() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("l", NTInteger).in("d", NTFloat).in("b", NTBoolean).out(NTString).build();
    // When
    CallableUserFunction concatMethod = compileFunction(signature, emptyList(), method("concat", long.class, Double.class, boolean.class));
    // Then
    assertEquals(stringValue("421.1true"), concatMethod.apply(ctx, new AnyValue[] { longValue(42), doubleValue(1.1), booleanValue(true) }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Aggregations

CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)28 Test (org.junit.jupiter.api.Test)23 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)14 AnyValue (org.neo4j.values.AnyValue)10 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 Log (org.neo4j.logging.Log)5 NullLog (org.neo4j.logging.NullLog)4 Collections.emptyList (java.util.Collections.emptyList)3 List (java.util.List)3 Method (java.lang.reflect.Method)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 NTList (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList)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 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)2 FailedLoadFunction (org.neo4j.kernel.api.procedure.FailedLoadFunction)2 UserFunction (org.neo4j.procedure.UserFunction)2