Search in sources :

Example 11 with TextArray

use of org.neo4j.values.storable.TextArray 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)

Aggregations

TextArray (org.neo4j.values.storable.TextArray)11 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)3 AnyValue (org.neo4j.values.AnyValue)3 StoreFailureException (org.neo4j.exceptions.StoreFailureException)2 Label (org.neo4j.graphdb.Label)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 MapValue (org.neo4j.values.virtual.MapValue)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Matcher (org.hamcrest.Matcher)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1