private void checkReadablePosition(int position) { if (position < 0 || position >= getPositionCount()) { throw new IllegalArgumentException("position is not valid"); } } }
@Override public long getRegionSizeInBytes(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int startFieldBlockOffset = getFieldBlockOffset(position); int endFieldBlockOffset = getFieldBlockOffset(position + length); int fieldBlockLength = endFieldBlockOffset - startFieldBlockOffset; long regionSizeInBytes = (Integer.BYTES + Byte.BYTES) * (long) length; for (int i = 0; i < numFields; i++) { regionSizeInBytes += getRawFieldBlocks()[i].getRegionSizeInBytes(startFieldBlockOffset, fieldBlockLength); } return regionSizeInBytes; }
@Override public Block getRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); return createRowBlockInternal(position + getOffsetBase(), length, getRowIsNull(), getFieldBlockOffsets(), getRawFieldBlocks()); }
@Override public long getPositionsSizeInBytes(boolean[] positions) { checkValidPositions(positions, getPositionCount()); int usedPositionCount = 0; boolean[] fieldPositions = new boolean[getRawFieldBlocks()[0].getPositionCount()]; for (int i = 0; i < positions.length; i++) { if (positions[i]) { usedPositionCount++; int startFieldBlockOffset = getFieldBlockOffset(i); int endFieldBlockOffset = getFieldBlockOffset(i + 1); for (int j = startFieldBlockOffset; j < endFieldBlockOffset; j++) { fieldPositions[j] = true; } } } long sizeInBytes = 0; for (int j = 0; j < numFields; j++) { sizeInBytes += getRawFieldBlocks()[j].getPositionsSizeInBytes(fieldPositions); } return sizeInBytes + (Integer.BYTES + Byte.BYTES) * (long) usedPositionCount; }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { AbstractRowBlock rowBlock = (AbstractRowBlock) block; int numFields = rowBlock.numFields; int positionCount = rowBlock.getPositionCount(); int offsetBase = rowBlock.getOffsetBase(); int[] fieldBlockOffsets = rowBlock.getFieldBlockOffsets(); int startFieldBlockOffset = fieldBlockOffsets[offsetBase]; int endFieldBlockOffset = fieldBlockOffsets[offsetBase + positionCount]; sliceOutput.appendInt(numFields); for (int i = 0; i < numFields; i++) { blockEncodingSerde.writeBlock(sliceOutput, rowBlock.getRawFieldBlocks()[i].getRegion(startFieldBlockOffset, endFieldBlockOffset - startFieldBlockOffset)); } sliceOutput.appendInt(positionCount); for (int position = 0; position < positionCount + 1; position++) { sliceOutput.writeInt(fieldBlockOffsets[offsetBase + position] - startFieldBlockOffset); } EncoderUtil.encodeNullsAsBits(sliceOutput, block); }
@Override public Block copyRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int startFieldBlockOffset = getFieldBlockOffset(position); int endFieldBlockOffset = getFieldBlockOffset(position + length); int fieldBlockLength = endFieldBlockOffset - startFieldBlockOffset; Block[] newBlocks = new Block[numFields]; for (int i = 0; i < numFields; i++) { newBlocks[i] = getRawFieldBlocks()[i].copyRegion(startFieldBlockOffset, fieldBlockLength); } int[] newOffsets = compactOffsets(getFieldBlockOffsets(), position + getOffsetBase(), length); boolean[] rowIsNull = getRowIsNull(); boolean[] newRowIsNull = rowIsNull == null ? null : compactArray(rowIsNull, position + getOffsetBase(), length); if (arraySame(newBlocks, getRawFieldBlocks()) && newOffsets == getFieldBlockOffsets() && newRowIsNull == rowIsNull) { return this; } return createRowBlockInternal(0, length, newRowIsNull, newOffsets, newBlocks); }