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());
}
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());
}
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));
}
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) }));
}
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));
}
Aggregations