Search in sources :

Example 1 with ByteArrayBlock

use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.

the class BooleanSelectiveColumnReader method mergeBlocks.

@Override
public Block<Byte> mergeBlocks(List<Block<Byte>> blocks, int positionCount) {
    byte[] valuesCopy = new byte[positionCount];
    boolean[] nullsCopy = new boolean[positionCount];
    AtomicInteger index = new AtomicInteger(0);
    blocks.stream().forEach(block -> {
        for (int i = 0; i < block.getPositionCount(); i++) {
            nullsCopy[index.get()] = block.isNull(i);
            valuesCopy[index.getAndIncrement()] = block.getByte(i, 0);
        }
    });
    return new ByteArrayBlock(positionCount, Optional.empty(), valuesCopy);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock)

Example 2 with ByteArrayBlock

use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.

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 }));
}
Also used : ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) SingleRowBlock(io.prestosql.spi.block.SingleRowBlock) Block(io.prestosql.spi.block.Block) ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 3 with ByteArrayBlock

use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.

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));
}
Also used : SingleMapBlock(io.prestosql.spi.block.SingleMapBlock) ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 4 with ByteArrayBlock

use of io.prestosql.spi.block.ByteArrayBlock in project boostkit-bigdata by kunpengcompute.

the class OperatorUtils method buildByteArrayBlock.

private static Block buildByteArrayBlock(Block block, int positionCount) {
    BooleanVec booleanVec = (BooleanVec) block.getValues();
    byte[] bytes = booleanVec.getValuesBuf().getBytes(booleanVec.getOffset(), positionCount);
    return new ByteArrayBlock(positionCount, Optional.of(booleanVec.getValuesNulls(0, positionCount)), bytes);
}
Also used : ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) BooleanVec(nova.hetu.omniruntime.vector.BooleanVec)

Example 5 with ByteArrayBlock

use of io.prestosql.spi.block.ByteArrayBlock in project hetu-core by openlookeng.

the class BooleanSelectiveColumnReader 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");
    if (allNulls) {
        return new RunLengthEncodedBlock(BOOLEAN.createBlockBuilder(null, 1).appendNull().build(), outputPositionCount);
    }
    if (positionCount == outputPositionCount) {
        Block block = new ByteArrayBlock(positionCount, Optional.ofNullable(nulls), values);
        nulls = null;
        values = null;
        return block;
    }
    byte[] valuesCopy = new byte[positionCount];
    boolean[] nullsCopy = null;
    if (nullsAllowed && presentStream != null) {
        nullsCopy = new boolean[positionCount];
    }
    int positionIndex = 0;
    int nextPosition = positions[positionIndex];
    for (int i = 0; i < outputPositionCount; i++) {
        if (outputPositions[i] < nextPosition) {
            continue;
        }
        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(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) ByteArrayBlock(io.prestosql.spi.block.ByteArrayBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Aggregations

ByteArrayBlock (io.prestosql.spi.block.ByteArrayBlock)7 Block (io.prestosql.spi.block.Block)4 Test (org.testng.annotations.Test)4 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)1 BlockAssertions.createStringsBlock (io.prestosql.block.BlockAssertions.createStringsBlock)1 ArrayBlock.fromElementBlock (io.prestosql.spi.block.ArrayBlock.fromElementBlock)1 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)1 SingleMapBlock (io.prestosql.spi.block.SingleMapBlock)1 SingleRowBlock (io.prestosql.spi.block.SingleRowBlock)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BooleanVec (nova.hetu.omniruntime.vector.BooleanVec)1