Search in sources :

Example 6 with SegmentInfo

use of org.apache.carbondata.core.metadata.blocklet.SegmentInfo in project carbondata by apache.

the class BlockIndexTest method testBuild.

@Test
public void testBuild() {
    segmentInfo = new SegmentInfo();
    new MockUp<BlockletBTreeBuilder>() {

        @Mock
        public void build(BTreeBuilderInfo segmentBuilderInfos) {
        }
    };
    int expectedValue = 0;
    BlockIndex blockIndex = new BlockIndex();
    columnSchema.setColumnName("employeeName");
    columnSchemaList.add(new ColumnSchema());
    footer.setSegmentInfo(segmentInfo);
    footer.setColumnInTable(columnSchemaList);
    footer.setBlockletList(Arrays.asList(blockletInfo));
    footerList.add(footer);
    blockIndex.buildIndex(footerList);
    assertEquals(footerList.get(0).getNumberOfRows(), expectedValue);
}
Also used : BTreeBuilderInfo(org.apache.carbondata.core.datastore.BTreeBuilderInfo) SegmentInfo(org.apache.carbondata.core.metadata.blocklet.SegmentInfo) MockUp(mockit.MockUp) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Test(org.junit.Test)

Example 7 with SegmentInfo

use of org.apache.carbondata.core.metadata.blocklet.SegmentInfo in project carbondata by apache.

the class AbstractDataFileFooterConverter method getIndexInfo.

/**
   * Below method will be used to get the index info from index file
   *
   * @param filePath           file path of the index file
   * @param tableBlockInfoList table block index
   * @return list of index info
   * @throws IOException problem while reading the index file
   */
public List<DataFileFooter> getIndexInfo(String filePath, List<TableBlockInfo> tableBlockInfoList) throws IOException {
    CarbonIndexFileReader indexReader = new CarbonIndexFileReader();
    List<DataFileFooter> dataFileFooters = new ArrayList<DataFileFooter>();
    try {
        // open the reader
        indexReader.openThriftReader(filePath);
        // get the index header
        org.apache.carbondata.format.IndexHeader readIndexHeader = indexReader.readIndexHeader();
        List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>();
        List<org.apache.carbondata.format.ColumnSchema> table_columns = readIndexHeader.getTable_columns();
        for (int i = 0; i < table_columns.size(); i++) {
            columnSchemaList.add(thriftColumnSchmeaToWrapperColumnSchema(table_columns.get(i)));
        }
        // get the segment info
        SegmentInfo segmentInfo = getSegmentInfo(readIndexHeader.getSegment_info());
        BlockletIndex blockletIndex = null;
        int counter = 0;
        int index = 0;
        DataFileFooter dataFileFooter = null;
        // read the block info from file
        while (indexReader.hasNext()) {
            BlockIndex readBlockIndexInfo = indexReader.readBlockIndexInfo();
            blockletIndex = getBlockletIndex(readBlockIndexInfo.getBlock_index());
            dataFileFooter = new DataFileFooter();
            TableBlockInfo tableBlockInfo = tableBlockInfoList.get(index);
            if (Integer.parseInt(CarbonTablePath.DataFileUtil.getPartNo(tableBlockInfo.getFilePath())) == counter++) {
                tableBlockInfo.setBlockOffset(readBlockIndexInfo.getOffset());
                tableBlockInfo.setVersion(ColumnarFormatVersion.valueOf((short) readIndexHeader.getVersion()));
                int blockletSize = getBlockletSize(readBlockIndexInfo);
                tableBlockInfo.getBlockletInfos().setNoOfBlockLets(blockletSize);
                dataFileFooter.setBlockletIndex(blockletIndex);
                dataFileFooter.setColumnInTable(columnSchemaList);
                dataFileFooter.setNumberOfRows(readBlockIndexInfo.getNum_rows());
                dataFileFooter.setBlockInfo(new BlockInfo(tableBlockInfo));
                dataFileFooter.setSegmentInfo(segmentInfo);
                dataFileFooters.add(dataFileFooter);
                if (++index == tableBlockInfoList.size()) {
                    break;
                }
            }
        }
    } finally {
        indexReader.closeThriftReader();
    }
    return dataFileFooters;
}
Also used : TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) CarbonIndexFileReader(org.apache.carbondata.core.reader.CarbonIndexFileReader) BlockletIndex(org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) BlockIndex(org.apache.carbondata.format.BlockIndex) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) BlockInfo(org.apache.carbondata.core.datastore.block.BlockInfo) TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) SegmentInfo(org.apache.carbondata.core.metadata.blocklet.SegmentInfo)

Aggregations

SegmentInfo (org.apache.carbondata.core.metadata.blocklet.SegmentInfo)7 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)5 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)5 ArrayList (java.util.ArrayList)3 BlockletInfo (org.apache.carbondata.core.metadata.blocklet.BlockletInfo)3 BlockletIndex (org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex)3 MockUp (mockit.MockUp)2 TableBlockInfo (org.apache.carbondata.core.datastore.block.TableBlockInfo)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 BTreeBuilderInfo (org.apache.carbondata.core.datastore.BTreeBuilderInfo)1 BlockInfo (org.apache.carbondata.core.datastore.block.BlockInfo)1 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)1 FileHolderImpl (org.apache.carbondata.core.datastore.impl.FileHolderImpl)1 CarbonIndexFileReader (org.apache.carbondata.core.reader.CarbonIndexFileReader)1 org.apache.carbondata.format (org.apache.carbondata.format)1 BlockIndex (org.apache.carbondata.format.BlockIndex)1 ColumnSchema (org.apache.carbondata.format.ColumnSchema)1