Search in sources :

Example 1 with AbstractArrayBlock

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

the class PrestoThriftBigintArray method fromBlock.

public static PrestoThriftBlock 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 PrestoThriftBigintArray(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);
        }
    }
    PrestoThriftBigint values = arrayBlock.apply((valuesBlock, startPosition, length) -> PrestoThriftBigint.fromBlock(valuesBlock), 0).getBigintData();
    checkState(values != null, "values must be present");
    checkState(totalSize(nulls, sizes) == values.numberOfRecords(), "unexpected number of values");
    return bigintArrayData(new PrestoThriftBigintArray(nulls, sizes, values));
}
Also used : BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Arrays(java.util.Arrays) ArrayBlock(com.facebook.presto.common.block.ArrayBlock) AbstractArrayBlock(com.facebook.presto.common.block.AbstractArrayBlock) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) ThriftStruct(com.facebook.drift.annotations.ThriftStruct) ThriftConstructor(com.facebook.drift.annotations.ThriftConstructor) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) OPTIONAL(com.facebook.drift.annotations.ThriftField.Requiredness.OPTIONAL) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PrestoThriftTypeUtils.sameSizeIfPresent(com.facebook.presto.thrift.api.datatypes.PrestoThriftTypeUtils.sameSizeIfPresent) PrestoThriftBlock.bigintArrayData(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock.bigintArrayData) Optional(java.util.Optional) PrestoThriftTypeUtils.totalSize(com.facebook.presto.thrift.api.datatypes.PrestoThriftTypeUtils.totalSize) ThriftField(com.facebook.drift.annotations.ThriftField) Block(com.facebook.presto.common.block.Block) PrestoThriftTypeUtils.calculateOffsets(com.facebook.presto.thrift.api.datatypes.PrestoThriftTypeUtils.calculateOffsets) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) AbstractArrayBlock(com.facebook.presto.common.block.AbstractArrayBlock)

Aggregations

ThriftConstructor (com.facebook.drift.annotations.ThriftConstructor)1 ThriftField (com.facebook.drift.annotations.ThriftField)1 OPTIONAL (com.facebook.drift.annotations.ThriftField.Requiredness.OPTIONAL)1 ThriftStruct (com.facebook.drift.annotations.ThriftStruct)1 AbstractArrayBlock (com.facebook.presto.common.block.AbstractArrayBlock)1 ArrayBlock (com.facebook.presto.common.block.ArrayBlock)1 Block (com.facebook.presto.common.block.Block)1 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 Type (com.facebook.presto.common.type.Type)1 PrestoThriftBlock.bigintArrayData (com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock.bigintArrayData)1 PrestoThriftTypeUtils.calculateOffsets (com.facebook.presto.thrift.api.datatypes.PrestoThriftTypeUtils.calculateOffsets)1 PrestoThriftTypeUtils.sameSizeIfPresent (com.facebook.presto.thrift.api.datatypes.PrestoThriftTypeUtils.sameSizeIfPresent)1 PrestoThriftTypeUtils.totalSize (com.facebook.presto.thrift.api.datatypes.PrestoThriftTypeUtils.totalSize)1 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 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1