use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.
the class Int32FlatBatchReader method readWithNull.
private ColumnChunk readWithNull() throws IOException {
int[] values = new int[nextBatchSize];
boolean[] isNull = new boolean[nextBatchSize];
int totalNonNullCount = 0;
int remainingInBatch = nextBatchSize;
int startOffset = 0;
while (remainingInBatch > 0) {
if (remainingCountInPage == 0) {
if (!readNextPage()) {
break;
}
}
int chunkSize = Math.min(remainingCountInPage, remainingInBatch);
int nonNullCount = definitionLevelDecoder.readNext(isNull, startOffset, chunkSize);
totalNonNullCount += nonNullCount;
if (nonNullCount > 0) {
valuesDecoder.readNext(values, startOffset, nonNullCount);
int valueDestinationIndex = startOffset + chunkSize - 1;
int valueSourceIndex = startOffset + nonNullCount - 1;
while (valueDestinationIndex >= startOffset) {
if (!isNull[valueDestinationIndex]) {
values[valueDestinationIndex] = values[valueSourceIndex];
valueSourceIndex--;
}
valueDestinationIndex--;
}
}
startOffset += chunkSize;
remainingInBatch -= chunkSize;
remainingCountInPage -= chunkSize;
}
if (remainingInBatch != 0) {
throw new ParquetDecodingException("Still remaining to be read in current batch.");
}
if (totalNonNullCount == 0) {
Block block = RunLengthEncodedBlock.create(field.getType(), null, nextBatchSize);
return new ColumnChunk(block, new int[0], new int[0]);
}
boolean hasNoNull = totalNonNullCount == nextBatchSize;
Block block = new IntArrayBlock(nextBatchSize, hasNoNull ? Optional.empty() : Optional.of(isNull), values);
return new ColumnChunk(block, new int[0], new int[0]);
}
use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.
the class Int32FlatBatchReader method readWithoutNull.
private ColumnChunk readWithoutNull() throws IOException {
int[] values = new int[nextBatchSize];
int remainingInBatch = nextBatchSize;
int startOffset = 0;
while (remainingInBatch > 0) {
if (remainingCountInPage == 0) {
if (!readNextPage()) {
break;
}
}
int chunkSize = Math.min(remainingCountInPage, remainingInBatch);
valuesDecoder.readNext(values, startOffset, chunkSize);
startOffset += chunkSize;
remainingInBatch -= chunkSize;
remainingCountInPage -= chunkSize;
}
if (remainingInBatch != 0) {
throw new ParquetDecodingException(format("Corrupted Parquet file: extra %d values to be consumed when scanning current batch", remainingInBatch));
}
Block block = new IntArrayBlock(nextBatchSize, Optional.empty(), values);
return new ColumnChunk(block, new int[0], new int[0]);
}
use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.
the class FloatSelectiveStreamReader method getBlockView.
@Override
public BlockLease getBlockView(int[] positions, int positionCount) {
checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
checkState(outputRequired, "This stream reader doesn't produce output");
checkState(positionCount <= outputPositionCount, "Not enough values");
checkState(!valuesInUse, "BlockLease hasn't been closed yet");
if (allNulls) {
return newLease(new RunLengthEncodedBlock(NULL_BLOCK, positionCount));
}
boolean includeNulls = nullsAllowed && presentStream != null;
if (positionCount != outputPositionCount) {
compactValues(positions, positionCount, includeNulls);
}
return newLease(new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values));
}
use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.
the class AbstractLongSelectiveStreamReader method getIntArrayBlock.
private Block getIntArrayBlock(int[] positions, int positionCount, boolean includeNulls) {
if (intValuesPopulated && positionCount == outputPositionCount) {
Block block = new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), intValues);
intValues = null;
nulls = null;
return block;
}
int[] valuesCopy = new int[positionCount];
boolean[] nullsCopy = null;
if (includeNulls) {
nullsCopy = new boolean[positionCount];
}
int positionIndex = 0;
int nextPosition = positions[positionIndex];
for (int i = 0; i < outputPositionCount; i++) {
if (outputPositions[i] < nextPosition) {
continue;
}
assert outputPositions[i] == nextPosition;
valuesCopy[positionIndex] = toIntExact(this.values[i]);
if (includeNulls) {
nullsCopy[positionIndex] = this.nulls[i];
}
positionIndex++;
if (positionIndex >= positionCount) {
break;
}
nextPosition = positions[positionIndex];
}
return new IntArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.
the class TestIntArrayBlock method testCompactBlock.
@Test
public void testCompactBlock() {
int[] intArray = { 0, 0, 1, 2, 3, 4 };
boolean[] valueIsNull = { false, true, false, false, false, false };
testCompactBlock(new IntArrayBlock(0, Optional.empty(), new int[0]));
testCompactBlock(new IntArrayBlock(intArray.length, Optional.of(valueIsNull), intArray));
testIncompactBlock(new IntArrayBlock(intArray.length - 1, Optional.of(valueIsNull), intArray));
}
Aggregations