@Override public ArrayBlock build() { if (currentEntryOpened) { throw new IllegalStateException("Current entry must be closed before the block can be built"); } return createArrayBlockInternal(0, positionCount, hasNullValue ? valueIsNull : null, offsets, values.build()); }
@Override public Block getLoadedBlock() { Block loadedValuesBlock = values.getLoadedBlock(); if (loadedValuesBlock == values) { return this; } return createArrayBlockInternal( arrayOffset, positionCount, valueIsNull, offsets, loadedValuesBlock); } }
@Override public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput) { Block values = blockEncodingSerde.readBlock(sliceInput); int positionCount = sliceInput.readInt(); int[] offsets = new int[positionCount + 1]; sliceInput.readBytes(Slices.wrappedIntArray(offsets)); boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElseGet(() -> new boolean[positionCount]); return createArrayBlockInternal(0, positionCount, valueIsNull, offsets, values); } }
@Override public Block getRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); return createArrayBlockInternal( position + getOffsetBase(), length, getValueIsNull(), getOffsets(), getRawElementBlock()); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); int startValueOffset = getOffset(position); int valueLength = getOffset(position + 1) - startValueOffset; Block newValues = getRawElementBlock().copyRegion(startValueOffset, valueLength); return createArrayBlockInternal( 0, 1, new boolean[] {isNull(position)}, new int[] {0, valueLength}, newValues); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); int[] newOffsets = new int[length + 1]; boolean[] newValueIsNull = new boolean[length]; IntArrayList valuesPositions = new IntArrayList(); int newPosition = 0; for (int i = offset; i < offset + length; ++i) { int position = positions[i]; if (isNull(position)) { newValueIsNull[newPosition] = true; newOffsets[newPosition + 1] = newOffsets[newPosition]; } else { int valuesStartOffset = getOffset(position); int valuesEndOffset = getOffset(position + 1); int valuesLength = valuesEndOffset - valuesStartOffset; newOffsets[newPosition + 1] = newOffsets[newPosition] + valuesLength; for (int elementIndex = valuesStartOffset; elementIndex < valuesEndOffset; elementIndex++) { valuesPositions.add(elementIndex); } } newPosition++; } Block newValues = getRawElementBlock().copyPositions(valuesPositions.elements(), 0, valuesPositions.size()); return createArrayBlockInternal(0, length, newValueIsNull, newOffsets, newValues); }
@Override public Block copyRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int startValueOffset = getOffset(position); int endValueOffset = getOffset(position + length); Block newValues = getRawElementBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset); int[] newOffsets = compactOffsets(getOffsets(), position + getOffsetBase(), length); boolean[] valueIsNull = getValueIsNull(); boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, position + getOffsetBase(), length); if (newValues == getRawElementBlock() && newOffsets == getOffsets() && newValueIsNull == valueIsNull) { return this; } return createArrayBlockInternal(0, length, newValueIsNull, newOffsets, newValues); }