Search in sources :

Example 26 with ListValue

use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.

the class InCacheTest method shouldTrackMemory.

@Test
void shouldTrackMemory() {
    // given
    InCache cache = new InCache();
    ListValue list = list(stringValue("a"), stringValue("b"), stringValue("c"));
    // when
    MemoryTracker memoryTracker = mock(MemoryTracker.class);
    cache.check(stringValue("a"), list, memoryTracker);
    // then
    ArgumentCaptor<Long> arg = ArgumentCaptor.forClass(Long.class);
    verify(memoryTracker).allocateHeap(arg.capture());
    assertThat(arg.getValue()).isGreaterThan(0);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) EmptyMemoryTracker(org.neo4j.memory.EmptyMemoryTracker) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 27 with ListValue

use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.

the class CypherFunctions method toSlice.

public static ListValue toSlice(AnyValue collection, AnyValue toValue) {
    assert collection != NO_VALUE && toValue != NO_VALUE : "NO_VALUE checks need to happen outside this call";
    int from = asInt(toValue);
    ListValue list = asList(collection);
    if (from >= 0) {
        return list.take(from);
    } else {
        return list.take(list.size() + from);
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue)

Example 28 with ListValue

use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.

the class PathValueBuilder method addMultipleUndirected.

/**
 * Adds multiple undirected relationships to the path
 *
 * @param relationships the undirected relationships to add
 */
@CalledFromGeneratedCode
public void addMultipleUndirected(ListValue relationships) {
    if (relationships.isEmpty()) {
        // nothing to add
        return;
    }
    long previous = nodes.get(nodes.size() - 1).id();
    RelationshipValue first = (RelationshipValue) relationships.head();
    boolean correctDirection = startNode(first, dbAccess, cursor).id() == previous || endNode(first, dbAccess, cursor).id() == previous;
    if (correctDirection) {
        for (AnyValue value : relationships) {
            if (notNoValue(value)) {
                addUndirectedWhenRelationshipsAreFullyLoaded((RelationshipValue) value);
            }
        }
    } else {
        ListValue reversed = relationships.reverse();
        for (AnyValue rel : reversed) {
            if (notNoValue(rel)) {
                addUndirectedWhenRelationshipsAreFullyLoaded((RelationshipValue) rel);
            }
        }
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Aggregations

ListValue (org.neo4j.values.virtual.ListValue)28 Test (org.junit.jupiter.api.Test)19 AnyValue (org.neo4j.values.AnyValue)14 ArrayList (java.util.ArrayList)3 LongValue (org.neo4j.values.storable.LongValue)3 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2 CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)2 BooleanValue (org.neo4j.values.storable.BooleanValue)2 Value (org.neo4j.values.storable.Value)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)2 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)1 EmptyMemoryTracker (org.neo4j.memory.EmptyMemoryTracker)1 MemoryTracker (org.neo4j.memory.MemoryTracker)1