use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
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.trino.spi.block.ByteArrayBlock in project trino by trinodb.
the class TestRowBlock method testFromFieldBlocksNoNullsDetection.
@Test
public void testFromFieldBlocksNoNullsDetection() {
Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
Block fieldBlock = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(5).getBytes());
boolean[] rowIsNull = new boolean[fieldBlock.getPositionCount()];
Arrays.fill(rowIsNull, false);
// Blocks may discard the null mask during creation if no values are null
assertFalse(fromFieldBlocks(5, Optional.of(rowIsNull), new Block[] { fieldBlock }).mayHaveNull());
// Last position is null must retain the nulls mask
rowIsNull[rowIsNull.length - 1] = true;
assertTrue(fromFieldBlocks(5, Optional.of(rowIsNull), new Block[] { fieldBlock }).mayHaveNull());
// Empty blocks have no nulls and can also discard their null mask
assertFalse(fromFieldBlocks(0, Optional.of(new boolean[0]), new Block[] { emptyBlock }).mayHaveNull());
// Normal blocks should have null masks preserved
List<Type> fieldTypes = ImmutableList.of(VARCHAR, BIGINT);
Block hasNullsBlock = createBlockBuilderWithValues(fieldTypes, alternatingNullValues(generateTestRows(fieldTypes, 100))).build();
assertTrue(hasNullsBlock.mayHaveNull());
}
use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
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 io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
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));
}
Aggregations