Search in sources :

Example 6 with UserFunctionSignature

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

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

Example 8 with UserFunctionSignature

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

the class ProcedureCompilationTest method shouldHandleNulls.

@Test
void shouldHandleNulls() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("b", NTBoolean).out(NTFloat).build();
    // When
    CallableUserFunction nullyMethod = compileFunction(signature, emptyList(), method("nullyMethod", Boolean.class));
    // Then
    assertEquals(Values.NO_VALUE, nullyMethod.apply(ctx, new AnyValue[] { TRUE }));
    assertEquals(PI, nullyMethod.apply(ctx, new AnyValue[] { Values.NO_VALUE }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) NTBoolean(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTBoolean) Test(org.junit.jupiter.api.Test)

Example 9 with UserFunctionSignature

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

the class ProcedureCompilationTest method shouldHandleNumberOutput.

@Test
void shouldHandleNumberOutput() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("numbers", NTList(NTNumber)).out(NTNumber).build();
    // When
    CallableUserFunction sumMethod = compileFunction(signature, emptyList(), method("sum", List.class));
    // Then
    assertEquals(longValue(3), sumMethod.apply(ctx, new AnyValue[] { list(longValue(1), longValue(2)) }));
}
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 10 with UserFunctionSignature

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

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