Search in sources :

Example 26 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class GenericIndexKeyValidator method worstCaseLength.

private static int worstCaseLength(AnyValue value) {
    if (value.isSequenceValue()) {
        SequenceValue sequenceValue = (SequenceValue) value;
        if (sequenceValue instanceof TextArray) {
            TextArray textArray = (TextArray) sequenceValue;
            int length = 0;
            for (int i = 0; i < textArray.length(); i++) {
                length += stringWorstCaseLength(textArray.stringValue(i).length());
            }
            return length;
        }
        return sequenceValue.length() * BIGGEST_STATIC_SIZE;
    } else {
        if (((Value) value).valueGroup().category() == ValueCategory.TEXT) {
            // For text, which is very dynamic in its nature do a worst-case off of number of characters in it
            return stringWorstCaseLength(((TextValue) value).length());
        }
        // For all else then use the biggest possible value for a non-dynamic, non-array value a state can occupy
        return BIGGEST_STATIC_SIZE;
    }
}
Also used : SequenceValue(org.neo4j.values.SequenceValue) AnyValue(org.neo4j.values.AnyValue) SequenceValue(org.neo4j.values.SequenceValue) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) TextArray(org.neo4j.values.storable.TextArray)

Example 27 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class ShortStringPropertyEncodeTest method encode.

private void encode(String string) {
    PropertyBlock block = new PropertyBlock();
    TextValue expectedValue = Values.stringValue(string);
    propertyStore.encodeValue(block, KEY_ID, expectedValue, CursorContext.NULL, INSTANCE);
    assertEquals(0, block.getValueRecords().size());
    Value readValue = block.getType().value(block, propertyStore, CursorContext.NULL);
    assertEquals(expectedValue, readValue);
}
Also used : TextValue(org.neo4j.values.storable.TextValue) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue)

Example 28 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class TransactionIT method shouldReadYourOwnWrites.

@Test
void shouldReadYourOwnWrites() throws Exception {
    var latch = new BinaryLatch();
    String bookmarkPrefix = null;
    try (var machine = newStateMachineAfterAuth()) {
        var recorder = new BoltResponseRecorder();
        machine.process(run("CREATE (n:A {prop:'one'})"), nullResponseHandler());
        machine.process(pullAll(), recorder);
        var bookmark = ((TextValue) recorder.nextResponse().metadata("bookmark")).stringValue();
        bookmarkPrefix = bookmark.split(":")[0];
    }
    var dbVersion = env.lastClosedTxId();
    var thread = new Thread(() -> {
        try (BoltStateMachine machine = newStateMachineAfterAuth()) {
            latch.await();
            var recorder = new BoltResponseRecorder();
            machine.process(run("MATCH (n:A) SET n.prop = 'two'", EMPTY_MAP), nullResponseHandler());
            machine.process(pullAll(), recorder);
        } catch (Throwable connectionFatality) {
            throw new RuntimeException(connectionFatality);
        }
    });
    thread.start();
    var dbVersionAfterWrite = dbVersion + 1;
    try (var machine = newStateMachineAfterAuth()) {
        var recorder = new BoltResponseRecorder();
        latch.release();
        var bookmark = bookmarkPrefix + ":" + dbVersionAfterWrite;
        machine.process(begin(env.databaseIdRepository(), asMapValue(singletonMap("bookmarks", List.of(bookmark)))), recorder);
        machine.process(run("MATCH (n:A) RETURN n.prop"), recorder);
        machine.process(pullAll(), recorder);
        machine.process(commit(), recorder);
        assertThat(recorder.nextResponse()).satisfies(succeeded());
        assertThat(recorder.nextResponse()).satisfies(succeeded());
        assertThat(recorder.nextResponse()).satisfies(succeededWithRecord("two"));
        assertThat(recorder.nextResponse()).satisfies(succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
    }
    thread.join();
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) TextValue(org.neo4j.values.storable.TextValue) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) BinaryLatch(org.neo4j.util.concurrent.BinaryLatch) Test(org.junit.jupiter.api.Test)

Example 29 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class IndexEntryTestUtil method generateStringValueResultingInIndexEntrySize.

public static <KEY extends NativeIndexKey<KEY>> TextValue generateStringValueResultingInIndexEntrySize(Layout<KEY, ?> layout, int size) {
    TextValue value;
    KEY key = layout.newKey();
    key.initialize(0);
    int stringLength = size;
    do {
        value = stringValue("A".repeat(stringLength--));
        key.initFromValue(0, value, NativeIndexKey.Inclusion.NEUTRAL);
    } while (layout.keySize(key) > size);
    assertEquals(size, layout.keySize(key));
    return value;
}
Also used : TextValue(org.neo4j.values.storable.TextValue)

Aggregations

TextValue (org.neo4j.values.storable.TextValue)29 Test (org.junit.jupiter.api.Test)12 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)7 AnyValue (org.neo4j.values.AnyValue)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BooleanValue (org.neo4j.values.storable.BooleanValue)6 Config (org.neo4j.configuration.Config)5 Value (org.neo4j.values.storable.Value)5 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Matchers.contains (org.hamcrest.Matchers.contains)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Public (org.neo4j.annotations.Public)4 CapabilitiesRegistry (org.neo4j.capabilities.CapabilitiesRegistry)4