Search in sources :

Example 1 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method metadataOf.

private MapValue metadataOf(AbstractCypherAdapterStream stream) throws Throwable {
    final MapValueBuilder meta = new MapValueBuilder();
    stream.handleRecords(new BoltResult.DiscardingRecordConsumer() {

        @Override
        public void addMetadata(String key, AnyValue value) {
            meta.add(key, value);
        }
    }, STREAM_LIMIT_UNLIMITED);
    return meta.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) AnyValue(org.neo4j.values.AnyValue)

Example 2 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class BuiltInProceduresTest method call.

private List<Object[]> call(String name, Object... args) throws ProcedureException, IndexNotFoundKernelException {
    DefaultValueMapper valueMapper = new DefaultValueMapper(mock(InternalTransaction.class));
    Context ctx = buildContext(resolver, valueMapper).withTransaction(transaction).withProcedureCallContext(callContext).context();
    when(graphDatabaseAPI.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(GraphDatabaseAPI.class)).thenReturn(graphDatabaseAPI);
    when(resolver.resolveDependency(GlobalProcedures.class)).thenReturn(procs);
    when(resolver.resolveDependency(IndexingService.class)).thenReturn(indexingService);
    when(schemaReadCore.indexGetPopulationProgress(any(IndexDescriptor.class))).thenReturn(PopulationProgress.DONE);
    AnyValue[] input = Arrays.stream(args).map(ValueUtils::of).toArray(AnyValue[]::new);
    int procId = procs.procedure(ProcedureSignature.procedureName(name.split("\\."))).id();
    List<AnyValue[]> anyValues = Iterators.asList(procs.callProcedure(ctx, procId, input, EMPTY_RESOURCE_TRACKER));
    List<Object[]> toReturn = new ArrayList<>(anyValues.size());
    for (AnyValue[] anyValue : anyValues) {
        Object[] values = new Object[anyValue.length];
        for (int i = 0; i < anyValue.length; i++) {
            AnyValue value = anyValue[i];
            values[i] = value.map(valueMapper);
        }
        toReturn.add(values);
    }
    return toReturn;
}
Also used : SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) AnyValue(org.neo4j.values.AnyValue) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DefaultValueMapper(org.neo4j.kernel.impl.util.DefaultValueMapper)

Example 3 with AnyValue

use of org.neo4j.values.AnyValue 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 4 with AnyValue

use of org.neo4j.values.AnyValue 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 AnyValue

use of org.neo4j.values.AnyValue 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

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5