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);
}
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));
}
}
Aggregations