Search in sources :

Example 6 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class ArrayConcatFunction method concat.

@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
    int resultPositionCount = 0;
    // fast path when there is at most one non empty block
    Block nonEmptyBlock = null;
    for (int i = 0; i < blocks.length; i++) {
        resultPositionCount += blocks[i].getPositionCount();
        if (blocks[i].getPositionCount() > 0) {
            nonEmptyBlock = blocks[i];
        }
    }
    if (nonEmptyBlock == null) {
        return blocks[0];
    }
    if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
        return nonEmptyBlock;
    }
    PageBuilder pageBuilder = (PageBuilder) state;
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
        Block block = blocks[blockIndex];
        for (int i = 0; i < block.getPositionCount(); i++) {
            elementType.appendTo(block, i, blockBuilder);
        }
    }
    pageBuilder.declarePositions(resultPositionCount);
    return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
Also used : Block(io.prestosql.spi.block.Block) PageBuilder(io.prestosql.spi.PageBuilder) BlockBuilder(io.prestosql.spi.block.BlockBuilder) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Example 7 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, long value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeLong(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Example 8 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Object value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeObject(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Example 9 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class ArrayConcatUtils method prependElement.

@UsedByGeneratedCode
public static Block prependElement(Type elementType, long value, Block block) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    elementType.writeLong(blockBuilder, value);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Example 10 with UsedByGeneratedCode

use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, boolean value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeBoolean(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode)

Aggregations

UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)38 BlockBuilder (io.prestosql.spi.block.BlockBuilder)20 PrestoException (io.prestosql.spi.PrestoException)12 SingleMapBlock (io.prestosql.spi.block.SingleMapBlock)10 JsonParser (com.fasterxml.jackson.core.JsonParser)5 JsonCastException (io.prestosql.util.JsonCastException)5 JsonUtil.createJsonParser (io.prestosql.util.JsonUtil.createJsonParser)5 PageBuilder (io.prestosql.spi.PageBuilder)4 Block (io.prestosql.spi.block.Block)4 IOException (java.io.IOException)4 Slice (io.airlift.slice.Slice)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)2 SliceOutput (io.airlift.slice.SliceOutput)2 TypedSet (io.prestosql.operator.aggregation.TypedSet)2 Type (io.prestosql.spi.type.Type)2 JsonUtil.createJsonGenerator (io.prestosql.util.JsonUtil.createJsonGenerator)2 BigDecimal (java.math.BigDecimal)2 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 QueryState (io.prestosql.execution.QueryState)1