use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class TestMapBlock method testCompactBlock.
@Test
public void testCompactBlock() {
Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
Block compactKeyBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
Block compactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
Block inCompactKeyBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
Block inCompactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
int[] offsets = { 0, 1, 1, 2, 4, 8, 16 };
boolean[] mapIsNull = { false, true, false, false, false, false };
testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(0, Optional.empty(), new int[1], emptyBlock, emptyBlock));
testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(mapIsNull.length, Optional.of(mapIsNull), offsets, compactKeyBlock, compactValueBlock));
// TODO: Add test case for a sliced MapBlock
// underlying key/value block is not compact
testIncompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(mapIsNull.length, Optional.of(mapIsNull), offsets, inCompactKeyBlock, inCompactValueBlock));
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class ByteSelectiveStreamReader method getBlock.
@Override
public Block getBlock(int[] positions, int positionCount) {
checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
checkState(outputRequired, "This stream reader doesn't produce output");
checkState(positionCount <= outputPositionCount, "Not enough values");
checkState(!valuesInUse, "BlockLease hasn't been closed yet");
if (allNulls) {
return new RunLengthEncodedBlock(NULL_BLOCK, positionCount);
}
boolean includeNulls = nullsAllowed && presentStream != null;
if (positionCount == outputPositionCount) {
Block block = new ByteArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
nulls = null;
values = null;
return block;
}
byte[] valuesCopy = new byte[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] = this.values[i];
if (nullsCopy != null) {
nullsCopy[positionIndex] = this.nulls[i];
}
positionIndex++;
if (positionIndex >= positionCount) {
break;
}
nextPosition = positions[positionIndex];
}
return new ByteArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Aggregations