Search in sources :

Example 1 with ArrayValue

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

the class GenericKeyStateTest method testDocumentedKeySizesArrays.

/**
 * If this test fails because size of index key has changed, documentation needs to be updated accordingly.
 */
@SuppressWarnings("DuplicateBranchesInSwitch")
@ParameterizedTest
@MethodSource("arrayValueGeneratorsStream")
void testDocumentedKeySizesArrays(ValueGenerator generator) {
    Value value = generator.next();
    GenericKey key = newKeyState();
    key.initFromValue(0, value, NEUTRAL);
    int keySize = key.size();
    int keyOverhead = GenericKey.ENTITY_ID_SIZE;
    int actualSizeOfData = keySize - keyOverhead;
    int arrayLength = 0;
    if (value instanceof ArrayValue) {
        arrayLength = ((ArrayValue) value).length();
    }
    int normalArrayOverhead = 3;
    int numberArrayOverhead = 4;
    int geometryArrayOverhead = 6;
    int arrayOverhead;
    int arrayElementSize;
    String typeName = value.getTypeName();
    switch(value.valueGroup()) {
        case NUMBER_ARRAY:
            arrayOverhead = numberArrayOverhead;
            arrayElementSize = getNumberArrayElementSize(value);
            break;
        case BOOLEAN_ARRAY:
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 1;
            break;
        case DATE_ARRAY:
            // typeName: Date
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 8;
            break;
        case ZONED_TIME_ARRAY:
            // typeName: Time
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 12;
            break;
        case LOCAL_TIME_ARRAY:
            // typeName: LocalTime
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 8;
            break;
        case ZONED_DATE_TIME_ARRAY:
            // typeName: DateTime
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 16;
            break;
        case LOCAL_DATE_TIME_ARRAY:
            // typeName: LocalDateTime
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 12;
            break;
        case DURATION_ARRAY:
            // typeName: Duration or Period
            arrayOverhead = normalArrayOverhead;
            arrayElementSize = 28;
            break;
        case GEOMETRY_ARRAY:
            arrayOverhead = geometryArrayOverhead;
            arrayElementSize = getGeometryArrayElementSize(value, arrayLength);
            break;
        case TEXT_ARRAY:
            assertTextArraySize(value, actualSizeOfData, normalArrayOverhead, typeName);
            return;
        default:
            throw new RuntimeException("Did not expect this type to be tested in this test. Value was " + value + " is value group " + value.valueGroup());
    }
    int expectedSizeOfData = arrayOverhead + arrayLength * arrayElementSize;
    assertKeySize(expectedSizeOfData, actualSizeOfData, typeName);
}
Also used : ArrayValue(org.neo4j.values.storable.ArrayValue) Value(org.neo4j.values.storable.Value) ByteValue(org.neo4j.values.storable.ByteValue) Values.isGeometryValue(org.neo4j.values.storable.Values.isGeometryValue) IntValue(org.neo4j.values.storable.IntValue) TextValue(org.neo4j.values.storable.TextValue) PointValue(org.neo4j.values.storable.PointValue) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) DoubleValue(org.neo4j.values.storable.DoubleValue) DurationValue(org.neo4j.values.storable.DurationValue) FloatValue(org.neo4j.values.storable.FloatValue) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) ShortValue(org.neo4j.values.storable.ShortValue) LongValue(org.neo4j.values.storable.LongValue) DateValue(org.neo4j.values.storable.DateValue) ArrayValue(org.neo4j.values.storable.ArrayValue) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with ArrayValue

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

the class PropertyStore method encodeValue.

public static void encodeValue(PropertyBlock block, int keyId, Value value, DynamicRecordAllocator stringAllocator, DynamicRecordAllocator arrayAllocator, boolean allowStorePointsAndTemporal, CursorContext cursorContext, MemoryTracker memoryTracker) {
    if (value instanceof ArrayValue) {
        Object asObject = value.asObject();
        // Try short array first, i.e. inlined in the property block
        if (ShortArray.encode(keyId, asObject, block, PropertyType.getPayloadSize())) {
            return;
        }
        // Fall back to dynamic array store
        List<DynamicRecord> arrayRecords = HeapTrackingCollections.newArrayList(memoryTracker);
        allocateArrayRecords(arrayRecords, asObject, arrayAllocator, allowStorePointsAndTemporal, cursorContext, memoryTracker);
        setSingleBlockValue(block, keyId, PropertyType.ARRAY, Iterables.first(arrayRecords).getId());
        for (DynamicRecord valueRecord : arrayRecords) {
            valueRecord.setType(PropertyType.ARRAY.intValue());
        }
        block.setValueRecords(arrayRecords);
    } else {
        value.writeTo(new PropertyBlockValueWriter(block, keyId, stringAllocator, allowStorePointsAndTemporal, cursorContext, memoryTracker));
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayValue(org.neo4j.values.storable.ArrayValue)

Aggregations

ArrayValue (org.neo4j.values.storable.ArrayValue)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)1 ByteValue (org.neo4j.values.storable.ByteValue)1 DateTimeValue (org.neo4j.values.storable.DateTimeValue)1 DateValue (org.neo4j.values.storable.DateValue)1 DoubleValue (org.neo4j.values.storable.DoubleValue)1 DurationValue (org.neo4j.values.storable.DurationValue)1 FloatValue (org.neo4j.values.storable.FloatValue)1 IntValue (org.neo4j.values.storable.IntValue)1 LocalDateTimeValue (org.neo4j.values.storable.LocalDateTimeValue)1 LocalTimeValue (org.neo4j.values.storable.LocalTimeValue)1 LongValue (org.neo4j.values.storable.LongValue)1 PointValue (org.neo4j.values.storable.PointValue)1 ShortValue (org.neo4j.values.storable.ShortValue)1 TextValue (org.neo4j.values.storable.TextValue)1 TimeValue (org.neo4j.values.storable.TimeValue)1 Value (org.neo4j.values.storable.Value)1 Values.isGeometryValue (org.neo4j.values.storable.Values.isGeometryValue)1