use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.
the class BooleanSelectiveColumnReader method mergeBlocks.
@Override
public Block<Byte> mergeBlocks(List<Block<Byte>> blocks, int positionCount) {
byte[] valuesCopy = new byte[positionCount];
boolean[] nullsCopy = new boolean[positionCount];
AtomicInteger index = new AtomicInteger(0);
blocks.stream().forEach(block -> {
for (int i = 0; i < block.getPositionCount(); i++) {
nullsCopy[index.get()] = block.isNull(i);
valuesCopy[index.getAndIncrement()] = block.getByte(i, 0);
}
});
return new ByteArrayBlock(positionCount, Optional.empty(), valuesCopy);
}
use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.
the class TestRowBlock method testCompactBlock.
@Test
public void testCompactBlock() {
Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
Block compactFieldBlock1 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(5).getBytes());
Block compactFieldBlock2 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(5).getBytes());
Block incompactFiledBlock1 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(6).getBytes());
Block incompactFiledBlock2 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(6).getBytes());
boolean[] rowIsNull = { false, true, false, false, false, false };
assertCompact(fromFieldBlocks(0, Optional.empty(), new Block[] { emptyBlock, emptyBlock }));
assertCompact(fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), new Block[] { compactFieldBlock1, compactFieldBlock2 }));
// TODO: add test case for a sliced RowBlock
// underlying field blocks are not compact
testIncompactBlock(fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), new Block[] { incompactFiledBlock1, incompactFiledBlock2 }));
testIncompactBlock(fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), new Block[] { incompactFiledBlock1, incompactFiledBlock2 }));
}
use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.
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(Optional.empty(), new int[1], emptyBlock, emptyBlock));
testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(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(Optional.of(mapIsNull), offsets, inCompactKeyBlock, inCompactValueBlock));
}
use of io.prestosql.spi.block.ByteArrayBlock in project boostkit-bigdata by kunpengcompute.
the class OperatorUtils method buildByteArrayBlock.
private static Block buildByteArrayBlock(Block block, int positionCount) {
BooleanVec booleanVec = (BooleanVec) block.getValues();
byte[] bytes = booleanVec.getValuesBuf().getBytes(booleanVec.getOffset(), positionCount);
return new ByteArrayBlock(positionCount, Optional.of(booleanVec.getValuesNulls(0, positionCount)), bytes);
}
use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.
the class BooleanSelectiveColumnReader 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");
if (allNulls) {
return new RunLengthEncodedBlock(BOOLEAN.createBlockBuilder(null, 1).appendNull().build(), outputPositionCount);
}
if (positionCount == outputPositionCount) {
Block block = new ByteArrayBlock(positionCount, Optional.ofNullable(nulls), values);
nulls = null;
values = null;
return block;
}
byte[] valuesCopy = new byte[positionCount];
boolean[] nullsCopy = null;
if (nullsAllowed && presentStream != null) {
nullsCopy = new boolean[positionCount];
}
int positionIndex = 0;
int nextPosition = positions[positionIndex];
for (int i = 0; i < outputPositionCount; i++) {
if (outputPositions[i] < nextPosition) {
continue;
}
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