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