Search in sources :

Example 1 with Block

use of io.prestosql.spi.block.Block in project carbondata by apache.

the class CarbondataPageSource method getNextPageForColumnar.

private Page getNextPageForColumnar() {
    if (nanoStart == 0) {
        nanoStart = System.nanoTime();
    }
    CarbonVectorBatch columnarBatch = null;
    int batchSize = 0;
    try {
        batchId++;
        if (vectorReader.nextKeyValue()) {
            Object vectorBatch = vectorReader.getCurrentValue();
            if (vectorBatch instanceof CarbonVectorBatch) {
                columnarBatch = (CarbonVectorBatch) vectorBatch;
                batchSize = columnarBatch.numRows();
                if (batchSize == 0) {
                    close();
                    return null;
                }
            }
        } else {
            close();
            return null;
        }
        if (columnarBatch == null) {
            return null;
        }
        Block[] blocks = new Block[columnHandles.size()];
        for (int column = 0; column < blocks.length; column++) {
            blocks[column] = new LazyBlock(batchSize, new CarbondataBlockLoader(column));
        }
        Page page = new Page(batchSize, blocks);
        return page;
    } catch (PrestoException e) {
        closeWithSuppression(e);
        throw e;
    } catch (RuntimeException e) {
        closeWithSuppression(e);
        throw new CarbonDataLoadingException("Exception when creating the Carbon data Block", e);
    }
}
Also used : LazyBlock(io.prestosql.spi.block.LazyBlock) CarbonDataLoadingException(org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException) LazyBlock(io.prestosql.spi.block.LazyBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) PrestoException(io.prestosql.spi.PrestoException)

Example 2 with Block

use of io.prestosql.spi.block.Block in project carbondata by apache.

the class ComplexTypeStreamReader method putComplexObject.

public void putComplexObject(List<Integer> offsetVector) {
    if (type instanceof ArrayType) {
        // build child block
        Block childBlock = buildChildBlock(getChildrenVector().get(0));
        // prepare an offset vector with 0 as initial offset
        int[] offsetVectorArray = new int[offsetVector.size() + 1];
        for (int i = 1; i <= offsetVector.size(); i++) {
            offsetVectorArray[i] = offsetVectorArray[i - 1] + offsetVector.get(i - 1);
        }
        // prepare Array block
        Block arrayBlock = ArrayBlock.fromElementBlock(offsetVector.size(), Optional.empty(), offsetVectorArray, childBlock);
        for (int position = 0; position < offsetVector.size(); position++) {
            type.writeObject(builder, arrayBlock.getObject(position, Block.class));
        }
        getChildrenVector().get(0).getColumnVector().reset();
    } else {
        // build child blocks
        List<Block> childBlocks = new ArrayList<>(getChildrenVector().size());
        for (CarbonColumnVector child : getChildrenVector()) {
            childBlocks.add(buildChildBlock(child));
        }
        // prepare ROW block
        Block rowBlock = RowBlock.fromFieldBlocks(offsetVector.size(), Optional.empty(), childBlocks.toArray(new Block[0]));
        for (int position = 0; position < offsetVector.size(); position++) {
            type.writeObject(builder, rowBlock.getObject(position, Block.class));
        }
        for (CarbonColumnVector child : getChildrenVector()) {
            child.getColumnVector().reset();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayBlock(io.prestosql.spi.block.ArrayBlock) RowBlock(io.prestosql.spi.block.RowBlock) Block(io.prestosql.spi.block.Block) CarbonColumnVector(org.apache.carbondata.core.scan.result.vector.CarbonColumnVector)

Example 3 with Block

use of io.prestosql.spi.block.Block in project carbondata by apache.

the class CarbondataPageSource method getNextPageForRow.

private Page getNextPageForRow() {
    if (isFrstPage) {
        isFrstPage = false;
        initialReaderForRow();
    }
    if (nanoStart == 0) {
        nanoStart = System.nanoTime();
    }
    int count = 0;
    try {
        Block[] blocks = new Block[columnCount];
        CarbonColumnVectorImpl[] columns = new CarbonColumnVectorImpl[columnCount];
        for (int i = 0; i < columnCount; ++i) {
            columns[i] = CarbonVectorBatch.createDirectStreamReader(batchSize, dataTypes[i], fields[i]);
        }
        while (rowReader.nextKeyValue()) {
            Object[] values = (Object[]) rowReader.getCurrentValue();
            for (int index = 0; index < columnCount; index++) {
                columns[index].putObject(count, values[index]);
            }
            count++;
            if (count == batchSize) {
                break;
            }
        }
        if (count == 0) {
            close();
            return null;
        } else {
            for (int index = 0; index < columnCount; index++) {
                blocks[index] = ((PrestoVectorBlockBuilder) columns[index]).buildBlock();
                sizeOfData += blocks[index].getSizeInBytes();
            }
        }
        return new Page(count, blocks);
    } catch (PrestoException e) {
        closeWithSuppression(e);
        throw e;
    } catch (RuntimeException | IOException e) {
        closeWithSuppression(e);
        throw new CarbonDataLoadingException("Exception when creating the Carbon data Block", e);
    }
}
Also used : CarbonDataLoadingException(org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException) CarbonColumnVectorImpl(org.apache.carbondata.core.scan.result.vector.impl.CarbonColumnVectorImpl) Page(io.prestosql.spi.Page) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) LazyBlock(io.prestosql.spi.block.LazyBlock) Block(io.prestosql.spi.block.Block)

Aggregations

Block (io.prestosql.spi.block.Block)3 Page (io.prestosql.spi.Page)2 PrestoException (io.prestosql.spi.PrestoException)2 LazyBlock (io.prestosql.spi.block.LazyBlock)2 CarbonDataLoadingException (org.apache.carbondata.processing.loading.exception.CarbonDataLoadingException)2 ArrayBlock (io.prestosql.spi.block.ArrayBlock)1 RowBlock (io.prestosql.spi.block.RowBlock)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CarbonColumnVector (org.apache.carbondata.core.scan.result.vector.CarbonColumnVector)1 CarbonColumnVectorImpl (org.apache.carbondata.core.scan.result.vector.impl.CarbonColumnVectorImpl)1