Search in sources :

Example 1 with LazyBlock

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);
    }
}
Also used : LazyBlock(com.facebook.presto.spi.block.LazyBlock) Block(com.facebook.presto.spi.block.Block) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) Page(com.facebook.presto.spi.Page) PrestoException(com.facebook.presto.spi.PrestoException) ColumnMapping(com.facebook.presto.hive.HivePageSourceProvider.ColumnMapping)

Example 2 with LazyBlock

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);
}
Also used : LazyBlock(com.facebook.presto.spi.block.LazyBlock) ImmutableSet(com.google.common.collect.ImmutableSet) Block(com.facebook.presto.spi.block.Block) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) Page(com.facebook.presto.spi.Page)

Example 3 with LazyBlock

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);
    }
}
Also used : Type(com.facebook.presto.spi.type.Type) LazyBlock(com.facebook.presto.spi.block.LazyBlock) Block(com.facebook.presto.spi.block.Block) LazyBlock(com.facebook.presto.spi.block.LazyBlock) Page(com.facebook.presto.spi.Page) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Example 4 with LazyBlock

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Page(com.facebook.presto.spi.Page) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) ParquetTypeUtils.getParquetType(com.facebook.presto.hive.parquet.ParquetTypeUtils.getParquetType) Type(com.facebook.presto.spi.type.Type) MessageType(parquet.schema.MessageType) LazyBlock(com.facebook.presto.spi.block.LazyBlock) Block(com.facebook.presto.spi.block.Block) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock)

Example 5 with LazyBlock

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);
    }
}
Also used : Type(com.facebook.presto.spi.type.Type) LazyBlock(com.facebook.presto.spi.block.LazyBlock) Block(com.facebook.presto.spi.block.Block) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) Utils.nativeValueToBlock(com.facebook.presto.spi.predicate.Utils.nativeValueToBlock) Page(com.facebook.presto.spi.Page) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Aggregations

Page (com.facebook.presto.spi.Page)5 Block (com.facebook.presto.spi.block.Block)5 LazyBlock (com.facebook.presto.spi.block.LazyBlock)5 PrestoException (com.facebook.presto.spi.PrestoException)4 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)4 Type (com.facebook.presto.spi.type.Type)3 IOException (java.io.IOException)3 ColumnMapping (com.facebook.presto.hive.HivePageSourceProvider.ColumnMapping)1 ParquetTypeUtils.getParquetType (com.facebook.presto.hive.parquet.ParquetTypeUtils.getParquetType)1 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)1 Utils.nativeValueToBlock (com.facebook.presto.spi.predicate.Utils.nativeValueToBlock)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 MessageType (parquet.schema.MessageType)1