Search in sources :

Example 1 with ShortArrayBlock

use of com.facebook.presto.common.block.ShortArrayBlock in project presto by prestodb.

the class TestShortArrayBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    short[] shortArray = { (short) 0, (short) 0, (short) 1, (short) 2, (short) 3, (short) 4 };
    boolean[] valueIsNull = { false, true, false, false, false, false };
    testCompactBlock(new ShortArrayBlock(0, Optional.empty(), new short[0]));
    testCompactBlock(new ShortArrayBlock(shortArray.length, Optional.of(valueIsNull), shortArray));
    testIncompactBlock(new ShortArrayBlock(shortArray.length - 1, Optional.of(valueIsNull), shortArray));
}
Also used : ShortArrayBlock(com.facebook.presto.common.block.ShortArrayBlock) Test(org.testng.annotations.Test)

Example 2 with ShortArrayBlock

use of com.facebook.presto.common.block.ShortArrayBlock in project presto by prestodb.

the class AbstractLongSelectiveStreamReader method getShortArrayBlock.

private Block getShortArrayBlock(int[] positions, int positionCount, boolean includeNulls) {
    if (shortValuesPopulated && positionCount == outputPositionCount) {
        Block block = new ShortArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), shortValues);
        shortValues = null;
        nulls = null;
        return block;
    }
    short[] valuesCopy = new short[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] = (short) this.values[i];
        if (includeNulls) {
            nullsCopy[positionIndex] = this.nulls[i];
        }
        positionIndex++;
        if (positionIndex >= positionCount) {
            break;
        }
        nextPosition = positions[positionIndex];
    }
    return new ShortArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) ShortArrayBlock(com.facebook.presto.common.block.ShortArrayBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Block(com.facebook.presto.common.block.Block) ShortArrayBlock(com.facebook.presto.common.block.ShortArrayBlock)

Aggregations

ShortArrayBlock (com.facebook.presto.common.block.ShortArrayBlock)2 Block (com.facebook.presto.common.block.Block)1 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)1 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)1 Test (org.testng.annotations.Test)1