private void ensureHashTableSize() { if (hashTables.length < offsets[positionCount] * HASH_MULTIPLIER) { int newSize = BlockUtil.calculateNewArraySize(offsets[positionCount] * HASH_MULTIPLIER); int oldSize = hashTables.length; hashTables = Arrays.copyOf(hashTables, newSize); Arrays.fill(hashTables, oldSize, hashTables.length, -1); } }
@Override public BlockBuilder newBlockBuilderLike(BlockBuilderStatus blockBuilderStatus) { int currentSizeInBytes = positions == 0 ? positions : (getOffset(positions) - getOffset(0)); return new VariableWidthBlockBuilder(blockBuilderStatus, calculateBlockResetSize(positions), calculateBlockResetBytes(currentSizeInBytes)); }
@Override public Block getPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); for (int i = offset; i < offset + length; i++) { checkValidPosition(positions[i], positionCount); } return new RunLengthEncodedBlock(value, length); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(positionCount, positionOffset, length); Slice newSlice = compactSlice(slice, positionOffset * fixedSize, length * fixedSize); Slice newValueIsNull = null; if (valueIsNull != null) { newValueIsNull = compactSlice(valueIsNull, positionOffset, length); } if (newSlice == slice && newValueIsNull == valueIsNull) { return this; } return new FixedWidthBlock(fixedSize, length, newSlice, newValueIsNull); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; int[] newOffsets = compactOffsets(offsets, positionOffset, length); Slice newSlice = compactSlice(slice, offsets[positionOffset], newOffsets[length]); boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); if (newOffsets == offsets && newSlice == slice && newValueIsNull == valueIsNull) { return this; } return new VariableWidthBlock(0, length, newSlice, newOffsets, newValueIsNull); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(positionCount, positionOffset, length); return new DictionaryBlock(idsOffset + positionOffset, length, dictionary, ids, false, dictionarySourceId); }
@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); }
@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); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); byte[] newValues = compactArray(values, positionOffset, length); if (newValueIsNull == valueIsNull && newValues == values) { return this; } return new ByteArrayBlock(0, length, newValueIsNull, newValues); }
/** * Create a new block from the current block by keeping the same elements * only with respect to {@code positions} that starts at {@code offset} and has length of {@code length}. * May return a view over the data in this block or may return a copy */ default Block getPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); return new DictionaryBlock(offset, length, this, positions, false, randomDictionaryId()); }
@Override public BlockBuilder newBlockBuilderLike(BlockBuilderStatus blockBuilderStatus) { return new ShortArrayBlockBuilder(blockBuilderStatus, calculateBlockResetSize(positionCount)); }
@Override public long getPositionsSizeInBytes(boolean[] positions) { checkValidPositions(positions, positionCount); boolean[] used = new boolean[dictionary.getPositionCount()]; for (int i = 0; i < positions.length; i++) { if (positions[i]) { used[getId(i)] = true; } } return dictionary.getPositionsSizeInBytes(used) + (Integer.BYTES * (long) countUsedPositions(positions)); }
public int getId(int position) { checkValidPosition(position, positionCount); return ids[position + idsOffset]; }
@Override public long getPositionsSizeInBytes(boolean[] positions) { checkValidPositions(positions, getPositionCount()); long sizeInBytes = 0; int usedPositionCount = 0; for (int i = 0; i < positions.length; ++i) { if (positions[i]) { usedPositionCount++; sizeInBytes += getOffset(i + 1) - getOffset(i); } } return sizeInBytes + (Integer.BYTES + Byte.BYTES) * (long) usedPositionCount; }
@Override public Block copyRegion(int positionOffset, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, positionOffset, length); int[] newOffsets = compactOffsets(offsets, positionOffset, length); boolean[] newValueIsNull = null; if (hasNullValue) { newValueIsNull = compactArray(valueIsNull, positionOffset, length); } Slice slice = compactSlice(sliceOutput.getUnderlyingSlice(), offsets[positionOffset], newOffsets[length]); return new VariableWidthBlock(0, length, slice, newOffsets, newValueIsNull); }
@Override public long getRegionSizeInBytes(int positionOffset, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, positionOffset, length); return (fixedSize + Byte.BYTES) * (long) length; }
@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 newKeys = getRawKeyBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset); Block newValues = getRawValueBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset); int[] newOffsets = compactOffsets(getOffsets(), position + getOffsetBase(), length); boolean[] mapIsNull = getMapIsNull(); boolean[] newMapIsNull = mapIsNull == null ? null : compactArray(mapIsNull, position + getOffsetBase(), length); int[] newHashTable = compactArray(getHashTables(), startValueOffset * HASH_MULTIPLIER, (endValueOffset - startValueOffset) * HASH_MULTIPLIER); if (newKeys == getRawKeyBlock() && newValues == getRawValueBlock() && newOffsets == getOffsets() && newMapIsNull == mapIsNull && newHashTable == getHashTables()) { return this; } return createMapBlockInternal( 0, length, Optional.ofNullable(newMapIsNull), newOffsets, newKeys, newValues, newHashTable, keyType, keyBlockNativeEquals, keyNativeHashCode); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); int[] newValues = compactArray(values, positionOffset, length); if (newValueIsNull == valueIsNull && newValues == values) { return this; } return new IntArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); boolean[] newValueIsNull = null; if (valueIsNull != null) { newValueIsNull = new boolean[length]; } long[] newValues = new long[length]; for (int i = 0; i < length; i++) { int position = positions[offset + i]; checkReadablePosition(position); if (valueIsNull != null) { newValueIsNull[i] = valueIsNull[position + arrayOffset]; } newValues[i] = values[position + arrayOffset]; } return new LongArrayBlock(0, length, newValueIsNull, newValues); }
@Override public BlockBuilder newBlockBuilderLike(BlockBuilderStatus blockBuilderStatus) { return new ByteArrayBlockBuilder(blockBuilderStatus, calculateBlockResetSize(positionCount)); }