use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.
the class FloatSelectiveColumnReader method getBlock.
@Override
public Block getBlock(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");
if (allNulls) {
return new RunLengthEncodedBlock(NULL_BLOCK, positionCount);
}
boolean includeNulls = nullsAllowed && presentStream != null;
if (positionCount == outputPositionCount) {
Block block = new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
nulls = null;
values = 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;
}
valuesCopy[positionIndex] = this.values[i];
if (nullsCopy != null) {
nullsCopy[positionIndex] = this.nulls[i];
}
positionIndex++;
if (positionIndex >= positionCount) {
break;
}
nextPosition = positions[positionIndex];
}
return new IntArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.
the class AbstractDecimalSelectiveColumnReader method getBlock.
@Override
public Block<T> getBlock(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");
if (allNulls) {
return new RunLengthEncodedBlock(nullBlock, outputPositionCount);
}
boolean includeNulls = nullsAllowed && presentStream != null;
if (positionCount == outputPositionCount) {
Block block = makeBlock(positionCount, nullsAllowed, nulls, values);
nulls = null;
values = null;
return block;
}
long[] valuesCopy = new long[valuesPerPosition * positionCount];
boolean[] nullsCopy = null;
if (includeNulls) {
nullsCopy = new boolean[positionCount];
}
copyValues(positions, positionCount, valuesCopy, nullsCopy);
return makeBlock(positionCount, includeNulls, nullsCopy, valuesCopy);
}
use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.
the class RcFileReader method readBlock.
public Block readBlock(int columnIndex) throws IOException {
checkArgument(readColumns.containsKey(columnIndex), "Column %s is not being read", columnIndex);
checkState(currentChunkRowCount > 0, "No more data");
if (columnIndex >= columns.length) {
Type type = readColumns.get(columnIndex);
Block nullBlock = type.createBlockBuilder(null, 1, 0).appendNull().build();
return new RunLengthEncodedBlock(nullBlock, currentChunkRowCount);
}
return columns[columnIndex].readBlock(rowGroupPosition, currentChunkRowCount);
}
use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.
the class RcFilePageSource method getNextPage.
@Override
public Page getNextPage() {
try {
// advance in the current batch
pageId++;
// if the batch has been consumed, read the next batch
int currentPageSize = rcFileReader.advance();
if (currentPageSize < 0) {
close();
return null;
}
Block[] blocks = new Block[hiveColumnIndexes.length];
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
if (constantBlocks[fieldId] != null) {
blocks[fieldId] = new RunLengthEncodedBlock(constantBlocks[fieldId], currentPageSize);
} else {
blocks[fieldId] = createBlock(currentPageSize, fieldId);
}
}
Page page = new Page(currentPageSize, blocks);
return page;
} catch (PrestoException e) {
closeWithSuppression(e);
throw e;
} catch (RcFileCorruptionException e) {
closeWithSuppression(e);
throw new PrestoException(HIVE_BAD_DATA, format("Corrupted RC file: %s", rcFileReader.getId()), e);
} catch (IOException | RuntimeException e) {
closeWithSuppression(e);
throw new PrestoException(HIVE_CURSOR_ERROR, format("Failed to read RC file: %s", rcFileReader.getId()), e);
}
}
use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.
the class BlockAssertions method createRLEBlock.
public static RunLengthEncodedBlock createRLEBlock(double value, int positionCount) {
BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1);
DOUBLE.writeDouble(blockBuilder, value);
return new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
}
Aggregations