use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
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 com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
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));
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class TestAggregationOperator method testDistinctMaskWithNull.
@Test
public void testDistinctMaskWithNull() {
AccumulatorFactory distinctFactory = COUNT.bind(ImmutableList.of(0), Optional.of(1), ImmutableList.of(BIGINT, BOOLEAN), ImmutableList.of(), ImmutableList.of(), null, // distinct
true, new JoinCompiler(MetadataManager.createTestMetadataManager(), new FeaturesConfig()), ImmutableList.of(), false, TEST_SESSION, new TempStorageStandaloneSpillerFactory(new TestingTempStorageManager(), new BlockEncodingManager(), new NodeSpillConfig(), new FeaturesConfig(), new SpillerStats()));
OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(distinctFactory), false);
DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
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> input = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(// all rows should be filtered by nulls
0L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of com.facebook.presto.common.block.ByteArrayBlock in project presto by prestodb.
the class BooleanSelectiveStreamReader 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 BooleanSelectiveStreamReader 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