use of com.facebook.presto.spi.block.LazyBlock in project presto by prestodb.
the class HivePageSource method getNextPage.
@Override
public Page getNextPage() {
try {
Block[] blocks = new Block[columnMappings.size()];
Page dataPage = delegate.getNextPage();
if (dataPage == null) {
return null;
}
int batchSize = dataPage.getPositionCount();
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
ColumnMapping columnMapping = columnMappings.get(fieldId);
if (columnMapping.isPrefilled()) {
blocks[fieldId] = RunLengthEncodedBlock.create(types[fieldId], prefilledValues[fieldId], batchSize);
} else {
blocks[fieldId] = dataPage.getBlock(columnMapping.getIndex());
if (coercers[fieldId] != null) {
blocks[fieldId] = new LazyBlock(batchSize, new CoercionLazyBlockLoader(blocks[fieldId], coercers[fieldId]));
}
}
}
return new Page(batchSize, blocks);
} catch (PrestoException e) {
closeWithSuppression(e);
throw e;
} catch (RuntimeException e) {
closeWithSuppression(e);
throw new PrestoException(HIVE_CURSOR_ERROR, e);
}
}
use of com.facebook.presto.spi.block.LazyBlock in project presto by prestodb.
the class GenericPageProcessor method getNonLazyPage.
private Page getNonLazyPage(Page page) {
ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
for (ProjectionFunction projection : projections) {
builder.addAll(projection.getInputChannels());
}
Set<Integer> inputChannels = builder.build();
if (inputChannels.isEmpty()) {
return page;
}
Block[] blocks = page.getBlocks();
for (int inputChannel : inputChannels) {
Block block = page.getBlock(inputChannel);
if (block instanceof LazyBlock) {
blocks[inputChannel] = ((LazyBlock) block).getBlock();
}
}
return new Page(blocks);
}
use of com.facebook.presto.spi.block.LazyBlock in project presto by prestodb.
the class OrcPageSource method getNextPage.
@Override
public Page getNextPage() {
try {
batchId++;
int batchSize = recordReader.nextBatch();
if (batchSize <= 0) {
close();
return null;
}
Block[] blocks = new Block[hiveColumnIndexes.length];
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
Type type = types.get(fieldId);
if (constantBlocks[fieldId] != null) {
blocks[fieldId] = constantBlocks[fieldId].getRegion(0, batchSize);
} else {
blocks[fieldId] = new LazyBlock(batchSize, new OrcBlockLoader(hiveColumnIndexes[fieldId], type));
}
}
return new Page(batchSize, blocks);
} catch (PrestoException e) {
closeWithSuppression(e);
throw e;
} catch (IOException | RuntimeException e) {
closeWithSuppression(e);
throw new PrestoException(HIVE_CURSOR_ERROR, e);
}
}
use of com.facebook.presto.spi.block.LazyBlock in project presto by prestodb.
the class ParquetPageSource method getNextPage.
@Override
public Page getNextPage() {
try {
batchId++;
long start = System.nanoTime();
int batchSize = parquetReader.nextBatch();
readTimeNanos += System.nanoTime() - start;
if (closed || batchSize <= 0) {
close();
return null;
}
Block[] blocks = new Block[hiveColumnIndexes.length];
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
if (constantBlocks[fieldId] != null) {
blocks[fieldId] = constantBlocks[fieldId].getRegion(0, batchSize);
} else {
Type type = types.get(fieldId);
int fieldIndex;
if (useParquetColumnNames) {
fieldIndex = getFieldIndex(fileSchema, columnNames.get(fieldId));
} else {
fieldIndex = hiveColumnIndexes[fieldId];
}
if (fieldIndex == -1) {
blocks[fieldId] = RunLengthEncodedBlock.create(type, null, batchSize);
continue;
}
String fieldName = fileSchema.getFields().get(fieldIndex).getName();
List<String> path = new ArrayList<>();
path.add(fieldName);
if (ROW.equals(type.getTypeSignature().getBase())) {
blocks[fieldId] = parquetReader.readStruct(type, path);
} else if (MAP.equals(type.getTypeSignature().getBase())) {
blocks[fieldId] = parquetReader.readMap(type, path);
} else if (ARRAY.equals(type.getTypeSignature().getBase())) {
blocks[fieldId] = parquetReader.readArray(type, path);
} else {
Optional<RichColumnDescriptor> descriptor = getDescriptor(fileSchema, requestedSchema, path);
if (descriptor.isPresent()) {
blocks[fieldId] = new LazyBlock(batchSize, new ParquetBlockLoader(descriptor.get(), type));
} else {
blocks[fieldId] = RunLengthEncodedBlock.create(type, null, batchSize);
}
}
}
}
return new Page(batchSize, blocks);
} catch (PrestoException e) {
closeWithSuppression(e);
throw e;
} catch (IOException | RuntimeException e) {
closeWithSuppression(e);
throw new PrestoException(HIVE_CURSOR_ERROR, e);
}
}
use of com.facebook.presto.spi.block.LazyBlock in project presto by prestodb.
the class OrcPageSource method getNextPage.
@Override
public Page getNextPage() {
try {
batchId++;
int batchSize = recordReader.nextBatch();
if (batchSize <= 0) {
close();
return null;
}
long filePosition = recordReader.getFilePosition();
Block[] blocks = new Block[columnIndexes.length];
for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
Type type = types.get(fieldId);
if (constantBlocks[fieldId] != null) {
blocks[fieldId] = constantBlocks[fieldId].getRegion(0, batchSize);
} else if (columnIndexes[fieldId] == ROWID_COLUMN) {
blocks[fieldId] = buildSequenceBlock(filePosition, batchSize);
} else {
blocks[fieldId] = new LazyBlock(batchSize, new OrcBlockLoader(columnIndexes[fieldId], type));
}
}
return new Page(batchSize, blocks);
} catch (IOException | RuntimeException e) {
closeWithSuppression(e);
throw new PrestoException(RAPTOR_ERROR, e);
}
}
Aggregations