Search in sources :

Example 1 with AbstractArrayBlock

use of io.trino.spi.block.AbstractArrayBlock in project trino by trinodb.

the class TrinoThriftBigintArray method fromBlock.

public static TrinoThriftBlock fromBlock(Block block) {
    checkArgument(block instanceof AbstractArrayBlock, "block is not of an array type");
    AbstractArrayBlock arrayBlock = (AbstractArrayBlock) block;
    int positions = arrayBlock.getPositionCount();
    if (positions == 0) {
        return bigintArrayData(new TrinoThriftBigintArray(null, null, null));
    }
    boolean[] nulls = null;
    int[] sizes = null;
    for (int position = 0; position < positions; position++) {
        if (arrayBlock.isNull(position)) {
            if (nulls == null) {
                nulls = new boolean[positions];
            }
            nulls[position] = true;
        } else {
            if (sizes == null) {
                sizes = new int[positions];
            }
            sizes[position] = arrayBlock.apply((valuesBlock, startPosition, length) -> length, position);
        }
    }
    TrinoThriftBigint values = arrayBlock.apply((valuesBlock, startPosition, length) -> TrinoThriftBigint.fromBlock(valuesBlock), 0).getBigintData();
    checkState(values != null, "values must be present");
    checkState(totalSize(nulls, sizes) == values.numberOfRecords(), "unexpected number of values");
    return bigintArrayData(new TrinoThriftBigintArray(nulls, sizes, values));
}
Also used : TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Arrays(java.util.Arrays) ThriftField(io.airlift.drift.annotations.ThriftField) TrinoThriftTypeUtils.sameSizeIfPresent(io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.sameSizeIfPresent) Type(io.trino.spi.type.Type) TrinoThriftBlock.bigintArrayData(io.trino.plugin.thrift.api.TrinoThriftBlock.bigintArrayData) OPTIONAL(io.airlift.drift.annotations.ThriftField.Requiredness.OPTIONAL) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TrinoThriftTypeUtils.calculateOffsets(io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.calculateOffsets) BIGINT(io.trino.spi.type.BigintType.BIGINT) Block(io.trino.spi.block.Block) TrinoThriftTypeUtils.totalSize(io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.totalSize) ThriftConstructor(io.airlift.drift.annotations.ThriftConstructor) Optional(java.util.Optional) ThriftStruct(io.airlift.drift.annotations.ThriftStruct) LongArrayBlock(io.trino.spi.block.LongArrayBlock) AbstractArrayBlock(io.trino.spi.block.AbstractArrayBlock) ArrayBlock(io.trino.spi.block.ArrayBlock) Nullable(javax.annotation.Nullable) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) AbstractArrayBlock(io.trino.spi.block.AbstractArrayBlock)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ThriftConstructor (io.airlift.drift.annotations.ThriftConstructor)1 ThriftField (io.airlift.drift.annotations.ThriftField)1 OPTIONAL (io.airlift.drift.annotations.ThriftField.Requiredness.OPTIONAL)1 ThriftStruct (io.airlift.drift.annotations.ThriftStruct)1 TrinoThriftBlock (io.trino.plugin.thrift.api.TrinoThriftBlock)1 TrinoThriftBlock.bigintArrayData (io.trino.plugin.thrift.api.TrinoThriftBlock.bigintArrayData)1 TrinoThriftTypeUtils.calculateOffsets (io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.calculateOffsets)1 TrinoThriftTypeUtils.sameSizeIfPresent (io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.sameSizeIfPresent)1 TrinoThriftTypeUtils.totalSize (io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.totalSize)1 AbstractArrayBlock (io.trino.spi.block.AbstractArrayBlock)1 ArrayBlock (io.trino.spi.block.ArrayBlock)1 Block (io.trino.spi.block.Block)1 LongArrayBlock (io.trino.spi.block.LongArrayBlock)1 BIGINT (io.trino.spi.type.BigintType.BIGINT)1 Type (io.trino.spi.type.Type)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1