@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new ShortArrayBlock( 0, 1, valueIsNull[position] ? new boolean[] {true} : null, new short[] {values[position]}); }
@Override public Block build() { if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, positionCount); } return new ShortArrayBlock(0, positionCount, valueIsNull, values); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new ShortArrayBlock( 0, 1, isNull(position) ? new boolean[] {true} : null, new short[] {values[position + arrayOffset]}); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); return new ShortArrayBlock(positionOffset + arrayOffset, length, valueIsNull, values); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } boolean[] newValueIsNull = null; if (hasNullValue) { newValueIsNull = Arrays.copyOfRange(valueIsNull, positionOffset, positionOffset + length); } short[] newValues = Arrays.copyOfRange(values, positionOffset, positionOffset + length); return new ShortArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput) { int positionCount = sliceInput.readInt(); boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElse(null); short[] values = new short[positionCount]; for (int position = 0; position < positionCount; position++) { if (valueIsNull == null || !valueIsNull[position]) { values[position] = sliceInput.readShort(); } } return new ShortArrayBlock(0, positionCount, valueIsNull, values); } }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); boolean[] newValueIsNull = null; if (valueIsNull != null) { newValueIsNull = new boolean[length]; } short[] newValues = new short[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 ShortArrayBlock(0, length, newValueIsNull, newValues); }
@Test public void testCompactBlock() { short[] shortArray = {(short) 0, (short) 0, (short) 1, (short) 2, (short) 3, (short) 4}; boolean[] valueIsNull = {false, true, false, false, false, false}; testCompactBlock(new ShortArrayBlock(0, Optional.empty(), new short[0])); testCompactBlock(new ShortArrayBlock(shortArray.length, Optional.of(valueIsNull), shortArray)); testIncompactBlock(new ShortArrayBlock(shortArray.length - 1, Optional.of(valueIsNull), shortArray)); }
@Test public void testCompactBlock() { short[] shortArray = {(short) 0, (short) 0, (short) 1, (short) 2, (short) 3, (short) 4}; boolean[] valueIsNull = {false, true, false, false, false, false}; testCompactBlock(new ShortArrayBlock(0, Optional.empty(), new short[0])); testCompactBlock(new ShortArrayBlock(shortArray.length, Optional.of(valueIsNull), shortArray)); testIncompactBlock(new ShortArrayBlock(shortArray.length - 1, Optional.of(valueIsNull), shortArray)); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new ShortArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); short[] newValues = compactArray(values, positionOffset, length); if (newValueIsNull == valueIsNull && newValues == values) { return this; } return new ShortArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } boolean[] newValueIsNull = null; if (hasNullValue) { newValueIsNull = new boolean[length]; } short[] newValues = new short[length]; for (int i = 0; i < length; i++) { int position = positions[offset + i]; checkReadablePosition(position); if (hasNullValue) { newValueIsNull[i] = valueIsNull[position]; } newValues[i] = values[position]; } return new ShortArrayBlock(0, length, newValueIsNull, newValues); }