Search in sources :

Example 6 with ByteArrayBlock

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());
}
Also used : Type(com.facebook.presto.common.type.Type) BlockAssertions.createRandomLongsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongsBlock) BlockAssertions.createRLEBlock(com.facebook.presto.block.BlockAssertions.createRLEBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) Block(com.facebook.presto.common.block.Block) SingleRowBlock(com.facebook.presto.common.block.SingleRowBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 7 with ByteArrayBlock

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));
}
Also used : ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) Block(com.facebook.presto.common.block.Block) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 8 with ByteArrayBlock

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);
}
Also used : JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) TempStorageStandaloneSpillerFactory(com.facebook.presto.spiller.TempStorageStandaloneSpillerFactory) NodeSpillConfig(com.facebook.presto.spiller.NodeSpillConfig) Page(com.facebook.presto.common.Page) SpillerStats(com.facebook.presto.spiller.SpillerStats) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TestingTempStorageManager(com.facebook.presto.testing.TestingTempStorageManager) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) AccumulatorFactory(com.facebook.presto.operator.aggregation.AccumulatorFactory) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) Block(com.facebook.presto.common.block.Block) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 9 with ByteArrayBlock

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));
}
Also used : ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 10 with ByteArrayBlock

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);
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) Block(com.facebook.presto.common.block.Block) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Aggregations

ByteArrayBlock (com.facebook.presto.common.block.ByteArrayBlock)12 Block (com.facebook.presto.common.block.Block)9 Test (org.testng.annotations.Test)8 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)6 BlockAssertions.createLongDictionaryBlock (com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock)4 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)4 BlockAssertions.createRandomLongsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongsBlock)4 BlockAssertions.createRandomDictionaryBlock (com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock)3 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)2 Page (com.facebook.presto.common.Page)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 SingleRowBlock (com.facebook.presto.common.block.SingleRowBlock)2 Type (com.facebook.presto.common.type.Type)2 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 Assertions.assertEqualsIgnoreOrder (com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder)1 Assertions.assertGreaterThan (com.facebook.airlift.testing.Assertions.assertGreaterThan)1 ExceededMemoryLimitException (com.facebook.presto.ExceededMemoryLimitException)1 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)1 RowPagesBuilder.rowPagesBuilder (com.facebook.presto.RowPagesBuilder.rowPagesBuilder)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1