use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
the class TestAggregationOperator method testMaskWithDirtyNulls.
@Test
public void testMaskWithDirtyNulls() {
List<Page> input = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, false, false }), new byte[] { 0, 27, /* dirty null */
0, 75 /* non-zero value is true */
})));
OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(COUNT.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1))));
DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(1L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
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.trino.spi.block.ByteArrayBlock in project trino by trinodb.
the class UnionColumnReader method getBlocks.
private Block[] getBlocks(int positionCount) throws IOException {
if (dataStream == null) {
throw new OrcCorruptionException(column.getOrcDataSourceId(), "Value is not null but data stream is missing");
}
Block[] blocks = new Block[fieldReaders.size() + 1];
byte[] tags = dataStream.next(positionCount);
blocks[0] = new ByteArrayBlock(positionCount, Optional.empty(), tags);
boolean[][] valueIsNonNull = new boolean[fieldReaders.size()][positionCount];
int[] nonNullValueCount = new int[fieldReaders.size()];
for (int i = 0; i < positionCount; i++) {
valueIsNonNull[tags[i]][i] = true;
nonNullValueCount[tags[i]]++;
}
for (int i = 0; i < fieldReaders.size(); i++) {
Type fieldType = type.getTypeParameters().get(i + 1);
if (nonNullValueCount[i] > 0) {
ColumnReader reader = fieldReaders.get(i);
reader.prepareNextRead(nonNullValueCount[i]);
Block rawBlock = blockFactory.createBlock(nonNullValueCount[i], reader::readBlock, true);
blocks[i + 1] = new LazyBlock(positionCount, new UnpackLazyBlockLoader(rawBlock, fieldType, valueIsNonNull[i]));
} else {
blocks[i + 1] = new RunLengthEncodedBlock(fieldType.createBlockBuilder(null, 1).appendNull().build(), positionCount);
}
}
return blocks;
}
use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
the class TestAggregationOperator method testDistinctMaskWithNulls.
@Test
public void testDistinctMaskWithNulls() {
AggregatorFactory distinctFactory = LONG_SUM.createDistinctAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1));
DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(distinctFactory));
ByteArrayBlock trueMaskAllNull = new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, true, true }), /* all positions are null */
new byte[] { 1, 1, 1, 1 });
/* non-zero value is true, all masks are true */
Block trueNullRleMask = new RunLengthEncodedBlock(trueMaskAllNull.getSingleValueBlock(0), 4);
List<Page> nullTrueMaskInput = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(10, 11, 10, 11), createBooleansBlock(true, true, true, true)), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(21L).build();
assertOperatorEquals(operatorFactory, driverContext, nullTrueMaskInput, expected);
}
use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.
the class TestBooleanType method testBooleanBlockWithoutNullsFromByteArray.
@Test
public void testBooleanBlockWithoutNullsFromByteArray() {
byte[] booleanBytes = new byte[4];
BlockBuilder builder = BOOLEAN.createFixedSizeBlockBuilder(booleanBytes.length);
for (int i = 0; i < booleanBytes.length; i++) {
boolean value = i % 2 == 0;
booleanBytes[i] = value ? (byte) 1 : 0;
BOOLEAN.writeBoolean(builder, value);
}
Block wrappedBlock = BooleanType.wrapByteArrayAsBooleanBlockWithoutNulls(booleanBytes);
Block builderBlock = builder.build();
// wrapped instances have no nulls
assertFalse(wrappedBlock.mayHaveNull());
// wrapped byte array instances and builder based instances both produce ByteArrayBlock
assertTrue(wrappedBlock instanceof ByteArrayBlock);
assertTrue(builderBlock instanceof ByteArrayBlock);
assertBlockEquals(BOOLEAN, wrappedBlock, builderBlock);
// the wrapping instance does not copy the byte array defensively
assertTrue(BOOLEAN.getBoolean(wrappedBlock, 0));
booleanBytes[0] = 0;
assertFalse(BOOLEAN.getBoolean(wrappedBlock, 0));
}
Aggregations