use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.
the class Procedures method start.
@Override
public void start() throws Throwable {
ProcedureJarLoader loader = new ProcedureJarLoader(compiler, log);
ProcedureJarLoader.Callables callables = loader.loadProceduresFromDir(pluginDir);
for (CallableProcedure procedure : callables.procedures()) {
register(procedure);
}
for (CallableUserFunction function : callables.functions()) {
register(function);
}
for (CallableUserAggregationFunction function : callables.aggregationFunctions()) {
register(function);
}
// And register built-in procedures
builtin.accept(this);
}
use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunUserAggregationFunctions.
@Test
public void shouldCompileAndRunUserAggregationFunctions() throws Throwable {
// Given
CallableUserAggregationFunction proc = compiler.compileAggregationFunction(AggregationFunctionWithInjectedAPI.class).get(0);
// When
proc.create(new BasicContext()).update(new Object[] {});
Object out = proc.create(new BasicContext()).result();
// Then
assertThat(out, equalTo("[Bonnie, Clyde]"));
}
use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.
@Test
public void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
// Given
List<CallableUserAggregationFunction> compiled = compile(MultiFunction.class);
CallableUserAggregationFunction f1 = compiled.get(0);
CallableUserAggregationFunction f2 = compiled.get(1);
// When
CallableUserAggregationFunction.Aggregator f1Aggregator = f1.create(new BasicContext());
f1Aggregator.update(new Object[] { "Bonnie" });
f1Aggregator.update(new Object[] { "Clyde" });
CallableUserAggregationFunction.Aggregator f2Aggregator = f2.create(new BasicContext());
f2Aggregator.update(new Object[] { "Bonnie", 1337L });
f2Aggregator.update(new Object[] { "Bonnie", 42L });
// Then
assertThat(f1Aggregator.result(), equalTo(Arrays.asList("Bonnie", "Clyde")));
assertThat(((Map) f2Aggregator.result()).get("Bonnie"), equalTo(1337L));
}
use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldSupportFunctionDeprecation.
@Test
public void shouldSupportFunctionDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
// When
List<CallableUserAggregationFunction> funcs = procedureCompiler.compileAggregationFunction(FunctionWithDeprecation.class);
// Then
verify(log).warn("Use of @UserAggregationFunction(deprecatedBy) without @Deprecated in org.neo4j.kernel.impl.proc.badFunc");
verifyNoMoreInteractions(log);
for (CallableUserAggregationFunction func : funcs) {
String name = func.signature().name().name();
func.create(new BasicContext());
switch(name) {
case "newFunc":
assertFalse("Should not be deprecated", func.signature().deprecated().isPresent());
break;
case "oldFunc":
case "badFunc":
assertTrue("Should be deprecated", func.signature().deprecated().isPresent());
assertThat(func.signature().deprecated().get(), equalTo("newFunc"));
break;
default:
fail("Unexpected function: " + name);
}
}
}
use of org.neo4j.kernel.api.proc.CallableUserAggregationFunction in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldRunAggregationFunction.
@Test
public void shouldRunAggregationFunction() throws Throwable {
// Given
CallableUserAggregationFunction func = compile(SingleAggregationFunction.class).get(0);
// When
CallableUserAggregationFunction.Aggregator aggregator = func.create(new BasicContext());
aggregator.update(new Object[] { "Harry" });
aggregator.update(new Object[] { "Bonnie" });
aggregator.update(new Object[] { "Sally" });
aggregator.update(new Object[] { "Clyde" });
// Then
assertThat(aggregator.result(), equalTo(Arrays.asList("Bonnie", "Clyde")));
}
Aggregations