use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class ByteSelectiveStreamReader method getBlockView.
@Override
public BlockLease getBlockView(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 newLease(new RunLengthEncodedBlock(NULL_BLOCK, positionCount));
}
boolean includeNulls = nullsAllowed && presentStream != null;
if (positionCount != outputPositionCount) {
compactValues(positions, positionCount, includeNulls);
}
return newLease(new ByteArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values));
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class TestHashAggregationOperator method testMask.
@Test
public void testMask() {
int positions = 4;
Block groupingBlock = RunLengthEncodedBlock.create(BIGINT, 1L, positions);
Block countBlock = RunLengthEncodedBlock.create(BIGINT, 1L, positions);
Block maskBlock = new ByteArrayBlock(positions, Optional.of(new boolean[] { false, false, true, true }), new byte[] { (byte) 0, (byte) 1, (byte) 0, (byte) 1 });
Page page = new Page(groupingBlock, countBlock, maskBlock);
HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), ImmutableList.of(0), ImmutableList.of(), Step.SINGLE, false, ImmutableList.of(COUNT.bind(ImmutableList.of(1), Optional.of(2))), Optional.empty(), Optional.empty(), 1, Optional.of(new DataSize(16, MEGABYTE)), false, new DataSize(16, MEGABYTE), new DataSize(16, MEGABYTE), new FailingSpillerFactory(), joinCompiler, false);
List<Page> outputPages = toPages(operatorFactory, createDriverContext(), ImmutableList.of(page)).stream().filter(p -> p.getPositionCount() > 0).collect(toImmutableList());
assertEquals(outputPages.size(), 1);
Page outputPage = outputPages.get(0);
assertEquals(outputPage.getBlock(0).getLong(0), 1L);
assertEquals(outputPage.getBlock(1).getLong(0), 1L);
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class TestArrayBlock method testCompactBlock.
@Test
public void testCompactBlock() {
Block emptyValueBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
Block compactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
Block inCompactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
int[] offsets = { 0, 1, 1, 2, 4, 8, 16 };
boolean[] valueIsNull = { false, true, false, false, false, false };
testCompactBlock(fromElementBlock(0, Optional.empty(), new int[1], emptyValueBlock));
testCompactBlock(fromElementBlock(valueIsNull.length, Optional.of(valueIsNull), offsets, compactValueBlock));
testIncompactBlock(fromElementBlock(valueIsNull.length - 1, Optional.of(valueIsNull), offsets, compactValueBlock));
// underlying value block is not compact
testIncompactBlock(fromElementBlock(valueIsNull.length, Optional.of(valueIsNull), offsets, inCompactValueBlock));
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class TestByteArrayBlock method testCompactBlock.
@Test
public void testCompactBlock() {
byte[] byteArray = { (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
boolean[] valueIsNull = { false, true, false, false, false, false };
testCompactBlock(new ByteArrayBlock(0, Optional.empty(), new byte[0]));
testCompactBlock(new ByteArrayBlock(byteArray.length, Optional.of(valueIsNull), byteArray));
testIncompactBlock(new ByteArrayBlock(byteArray.length - 1, Optional.of(valueIsNull), byteArray));
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
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 }));
}
Aggregations