use of com.facebook.presto.common.block.ShortArrayBlock in project presto by prestodb.
the class TestShortArrayBlock method testCompactBlock.
@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));
}
use of com.facebook.presto.common.block.ShortArrayBlock in project presto by prestodb.
the class AbstractLongSelectiveStreamReader method getShortArrayBlock.
private Block getShortArrayBlock(int[] positions, int positionCount, boolean includeNulls) {
if (shortValuesPopulated && positionCount == outputPositionCount) {
Block block = new ShortArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), shortValues);
shortValues = null;
nulls = null;
return block;
}
short[] valuesCopy = new short[positionCount];
boolean[] nullsCopy = null;
if (includeNulls) {
nullsCopy = new boolean[positionCount];
}
int positionIndex = 0;
int nextPosition = positions[positionIndex];
for (int i = 0; i < outputPositionCount; i++) {
if (outputPositions[i] < nextPosition) {
continue;
}
assert outputPositions[i] == nextPosition;
valuesCopy[positionIndex] = (short) this.values[i];
if (includeNulls) {
nullsCopy[positionIndex] = this.nulls[i];
}
positionIndex++;
if (positionIndex >= positionCount) {
break;
}
nextPosition = positions[positionIndex];
}
return new ShortArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Aggregations