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));
}
Aggregations