Search in sources :

Example 6 with ListValue

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

the class ValueUtilsTest method shouldHandleCollection.

@Test
void shouldHandleCollection() {
    // Given
    Collection<Integer> collection = Arrays.asList(1, 2, 3);
    // When
    AnyValue of = ValueUtils.of(collection);
    // Then
    assertThat(of).isInstanceOf(ListValue.class);
    ListValue listValue = (ListValue) of;
    assertThat(listValue.value(0)).isEqualTo(intValue(1));
    assertThat(listValue.value(1)).isEqualTo(intValue(2));
    assertThat(listValue.value(2)).isEqualTo(intValue(3));
    assertThat(listValue.size()).isEqualTo(3);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 7 with ListValue

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

the class HeapTrackingListValueBuilderTest method streamAndCollectElements.

@Test
void streamAndCollectElements() {
    int iterations = rnd.nextInt(10, 1000);
    ArrayList<LongValue> list = new ArrayList<>(iterations);
    for (int i = 0; i < iterations; i++) {
        list.add(Values.longValue(i));
    }
    var collector = HeapTrackingListValueBuilder.collector(memoryTracker);
    ListValue listValue = list.stream().collect(collector);
    // Validate value size
    long memoryTrackerActualSize = meter.measureDeep(memoryTracker);
    long actualValueSize = meter.measureDeep(listValue) - memoryTrackerActualSize;
    long estimatedValueSize = listValue.estimatedHeapUsage();
    assertEquals(actualValueSize, estimatedValueSize);
    // Validate items
    Iterator<AnyValue> iterator = listValue.iterator();
    for (int i = 0; i < iterations; i++) {
        assertTrue(iterator.hasNext());
        assertEquals(i, ((LongValue) iterator.next()).longValue());
    }
    assertFalse(iterator.hasNext());
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) LongValue(org.neo4j.values.storable.LongValue) ArrayList(java.util.ArrayList) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 8 with ListValue

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

the class BuiltInProceduresIT method dbIndexesResult.

private static AnyValue[] dbIndexesResult(long id, String name, String state, Double populationPercent, String uniqueness, String type, String entityType, List<String> labelsOrTypes, List<String> properties, String provider) {
    ListValue labelsOrTypesList = VirtualValues.list(labelsOrTypes.stream().map(Values::stringValue).toArray(AnyValue[]::new));
    ListValue propertiesList = VirtualValues.list(properties.stream().map(Values::stringValue).toArray(AnyValue[]::new));
    return new AnyValue[] { longValue(id), stringValue(name), stringValue(state), doubleValue(populationPercent), stringValue(uniqueness), stringValue(type), stringValue(entityType), labelsOrTypesList, propertiesList, stringValue(provider) };
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Values(org.neo4j.values.storable.Values) VirtualValues(org.neo4j.values.virtual.VirtualValues) AnyValue(org.neo4j.values.AnyValue)

Example 9 with ListValue

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

the class InCacheTest method shouldHandleListWithNoNulls.

@Test
void shouldHandleListWithNoNulls() {
    InCache cache = new InCache();
    ListValue list = list(stringValue("a"), stringValue("b"), stringValue("c"));
    Map<Value, Value> expected = Map.of(stringValue("a"), TRUE, stringValue("b"), TRUE, stringValue("c"), TRUE, stringValue("d"), FALSE, NO_VALUE, NO_VALUE);
    for (Entry<Value, Value> entry : shuffled(expected)) {
        assertThat(cache.check(entry.getKey(), list, EmptyMemoryTracker.INSTANCE)).isEqualTo(entry.getValue());
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) BooleanValue(org.neo4j.values.storable.BooleanValue) ListValue(org.neo4j.values.virtual.ListValue) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Values.intValue(org.neo4j.values.storable.Values.intValue) Test(org.junit.jupiter.api.Test)

Example 10 with ListValue

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

the class TextValueTest method split.

@ParameterizedTest
@MethodSource("functions")
void split(Function<String, TextValue> value) {
    assertThat(value.apply("HELLO").split("LL")).isEqualTo(stringArray("HE", "O"));
    assertThat(value.apply("Separating,by,comma,is,a,common,use,case").split(",")).isEqualTo(stringArray("Separating", "by", "comma", "is", "a", "common", "use", "case"));
    assertThat(value.apply("HELLO").split("HELLO")).isEqualTo(stringArray("", ""));
    // splitting on empty separator
    ListValue helloSplitOnEmpty = value.apply("HELLO").split("");
    assertThat(helloSplitOnEmpty).isEqualTo(Values.stringArray("H", "E", "L", "L", "O"));
    ArrayValue helloSplitOnEmptyStorable = helloSplitOnEmpty.toStorableArray();
    // is not CharArray
    assertThat(helloSplitOnEmptyStorable).isInstanceOf(StringArray.class);
    // is not char[]
    assertThat(helloSplitOnEmptyStorable.asObject()).isEqualTo(new String[] { "H", "E", "L", "L", "O" });
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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