Search in sources :

Example 11 with DataFileFooter

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

the class BTreeBlockFinderTest method getFileFooterListWithOnlyDictionaryKey.

private List<DataFileFooter> getFileFooterListWithOnlyDictionaryKey() {
    List<DataFileFooter> list = new ArrayList<DataFileFooter>();
    try {
        int[] dimensionBitLength = CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 });
        KeyGenerator multiDimKeyVarLengthGenerator = new MultiDimKeyVarLengthGenerator(dimensionBitLength);
        int i = 1;
        while (i < 1001) {
            byte[] startKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i, i });
            byte[] endKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i + 10, i + 10 });
            ByteBuffer buffer = ByteBuffer.allocate(1 + 4);
            buffer.rewind();
            buffer.put((byte) 1);
            buffer.putInt(i);
            buffer.array();
            byte[] noDictionaryStartKey = buffer.array();
            ByteBuffer buffer1 = ByteBuffer.allocate(1 + 4);
            buffer1.rewind();
            buffer1.put((byte) 1);
            buffer1.putInt(i + 10);
            buffer1.array();
            byte[] noDictionaryEndKey = buffer.array();
            DataFileFooter footer = getFileFooterWithOnlyDictionaryKey(startKey, endKey, noDictionaryStartKey, noDictionaryEndKey);
            list.add(footer);
            i = i + 10;
        }
    } catch (Exception e) {
        LOGGER.error(e);
    }
    return list;
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) ArrayList(java.util.ArrayList) KeyGenerator(org.apache.carbondata.core.keygenerator.KeyGenerator) ByteBuffer(java.nio.ByteBuffer) KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException)

Example 12 with DataFileFooter

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

the class BTreeBlockFinderTest method testBtreeSearchIsWorkingAndGivingPorperBlockletWithNoDictionary.

@Test
public void testBtreeSearchIsWorkingAndGivingPorperBlockletWithNoDictionary() {
    BtreeBuilder builder = new BlockBTreeBuilder();
    List<DataFileFooter> footerList = getFileFooterListWithOnlyNoDictionaryKey();
    BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null);
    builder.build(infos);
    DataRefNode dataBlock = builder.get();
    assertTrue(dataBlock != null);
    DataRefNodeFinder finder = new BTreeDataRefNodeFinder(new int[] { -1 }, 1, 1);
    ByteBuffer buffer = ByteBuffer.allocate(4 + 1);
    buffer.rewind();
    buffer.put((byte) 1);
    buffer.putInt(0);
    buffer.array();
    IndexKey key = new IndexKey(null, buffer.array());
    DataRefNode findFirstBlock = finder.findFirstDataBlock(dataBlock, key);
    assertEquals(0, findFirstBlock.nodeNumber());
    DataRefNode findLastBlock = finder.findLastDataBlock(dataBlock, key);
    assertEquals(0, findLastBlock.nodeNumber());
}
Also used : IndexKey(org.apache.carbondata.core.datastore.IndexKey) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) BTreeBuilderInfo(org.apache.carbondata.core.datastore.BTreeBuilderInfo) DataRefNode(org.apache.carbondata.core.datastore.DataRefNode) DataRefNodeFinder(org.apache.carbondata.core.datastore.DataRefNodeFinder) ByteBuffer(java.nio.ByteBuffer) BtreeBuilder(org.apache.carbondata.core.datastore.BtreeBuilder) Test(org.junit.Test)

Example 13 with DataFileFooter

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

the class BTreeBlockFinderTest method getFileFooterWithOnlyDictionaryKey.

private DataFileFooter getFileFooterWithOnlyDictionaryKey(byte[] startKey, byte[] endKey, byte[] noDictionaryStartKey, byte[] noDictionaryEndKey) {
    DataFileFooter footer = new DataFileFooter();
    BlockletIndex index = new BlockletIndex();
    BlockletBTreeIndex btreeIndex = new BlockletBTreeIndex();
    ByteBuffer buffer = ByteBuffer.allocate(4 + startKey.length + 4 + 0);
    buffer.putInt(startKey.length);
    buffer.putInt(0);
    buffer.put(startKey);
    buffer.rewind();
    btreeIndex.setStartKey(buffer.array());
    ByteBuffer buffer1 = ByteBuffer.allocate(4 + 0 + 4 + noDictionaryEndKey.length);
    buffer1.putInt(endKey.length);
    buffer1.putInt(0);
    buffer1.put(endKey);
    buffer1.rewind();
    btreeIndex.setEndKey(buffer1.array());
    BlockletMinMaxIndex minMax = new BlockletMinMaxIndex();
    minMax.setMaxValues(new byte[][] { endKey });
    minMax.setMinValues(new byte[][] { startKey });
    index.setBtreeIndex(btreeIndex);
    index.setMinMaxIndex(minMax);
    footer.setBlockletIndex(index);
    return footer;
}
Also used : BlockletBTreeIndex(org.apache.carbondata.core.metadata.blocklet.index.BlockletBTreeIndex) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) BlockletIndex(org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex) BlockletMinMaxIndex(org.apache.carbondata.core.metadata.blocklet.index.BlockletMinMaxIndex) ByteBuffer(java.nio.ByteBuffer)

Example 14 with DataFileFooter

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

the class CarbonUtilTest method testToReadMetadatFile.

@Test
public void testToReadMetadatFile() throws IOException {
    new MockUp<DataFileFooterConverter>() {

        @SuppressWarnings("unused")
        @Mock
        public DataFileFooter readDataFileFooter(TableBlockInfo info) {
            DataFileFooter fileFooter = new DataFileFooter();
            fileFooter.setVersionId(ColumnarFormatVersion.V1);
            return fileFooter;
        }
    };
    TableBlockInfo info = new TableBlockInfo("file:/", 1, "0", new String[0], 1, ColumnarFormatVersion.V1);
    assertEquals(CarbonUtil.readMetadatFile(info).getVersionId().number(), 1);
}
Also used : TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 15 with DataFileFooter

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

the class DataFileFooterConverterTest method testReadDataFileFooter.

@Test
public void testReadDataFileFooter() throws Exception {
    DataFileFooterConverter dataFileFooterConverter = new DataFileFooterConverter();
    DataFileFooter dataFileFooter = new DataFileFooter();
    List<Integer> column_cardinalities = new ArrayList<>();
    column_cardinalities.add(new Integer("1"));
    column_cardinalities.add(new Integer("2"));
    column_cardinalities.add(new Integer("3"));
    org.apache.carbondata.format.SegmentInfo segmentInfo1 = new org.apache.carbondata.format.SegmentInfo(3, column_cardinalities);
    List<Encoding> encoders = new ArrayList<>();
    encoders.add(Encoding.INVERTED_INDEX);
    encoders.add(Encoding.BIT_PACKED);
    encoders.add(Encoding.DELTA);
    encoders.add(Encoding.DICTIONARY);
    encoders.add(Encoding.DIRECT_DICTIONARY);
    encoders.add(Encoding.RLE);
    ColumnSchema columnSchema = new ColumnSchema(DataType.INT, "column", "3", true, encoders, true);
    ColumnSchema columnSchema1 = new ColumnSchema(DataType.ARRAY, "column", "3", true, encoders, true);
    ColumnSchema columnSchema2 = new ColumnSchema(DataType.DECIMAL, "column", "3", true, encoders, true);
    ColumnSchema columnSchema3 = new ColumnSchema(DataType.DOUBLE, "column", "3", true, encoders, true);
    ColumnSchema columnSchema4 = new ColumnSchema(DataType.LONG, "column", "3", true, encoders, true);
    ColumnSchema columnSchema5 = new ColumnSchema(DataType.SHORT, "column", "3", true, encoders, true);
    ColumnSchema columnSchema6 = new ColumnSchema(DataType.STRUCT, "column", "3", true, encoders, true);
    ColumnSchema columnSchema7 = new ColumnSchema(DataType.STRING, "column", "3", true, encoders, true);
    final List<ColumnSchema> columnSchemas = new ArrayList<>();
    columnSchemas.add(columnSchema);
    columnSchemas.add(columnSchema1);
    columnSchemas.add(columnSchema2);
    columnSchemas.add(columnSchema3);
    columnSchemas.add(columnSchema4);
    columnSchemas.add(columnSchema5);
    columnSchemas.add(columnSchema6);
    columnSchemas.add(columnSchema7);
    org.apache.carbondata.format.BlockletIndex blockletIndex1 = new org.apache.carbondata.format.BlockletIndex();
    List<org.apache.carbondata.format.BlockletIndex> blockletIndexArrayList = new ArrayList<>();
    blockletIndexArrayList.add(blockletIndex1);
    org.apache.carbondata.format.BlockletInfo blockletInfo = new org.apache.carbondata.format.BlockletInfo();
    List<org.apache.carbondata.format.BlockletInfo> blockletInfoArrayList = new ArrayList<>();
    blockletInfoArrayList.add(blockletInfo);
    final FileFooter fileFooter = new FileFooter(1, 3, columnSchemas, segmentInfo1, blockletIndexArrayList);
    fileFooter.setBlocklet_info_list(blockletInfoArrayList);
    BlockletBTreeIndex blockletBTreeIndex = new BlockletBTreeIndex();
    blockletBTreeIndex.setStart_key("1".getBytes());
    blockletBTreeIndex.setEnd_key("3".getBytes());
    blockletIndex1.setB_tree_index(blockletBTreeIndex);
    BlockletMinMaxIndex blockletMinMaxIndex = new BlockletMinMaxIndex();
    blockletMinMaxIndex.setMax_values(Arrays.asList(ByteBuffer.allocate(1).put((byte) 2)));
    blockletMinMaxIndex.setMin_values(Arrays.asList(ByteBuffer.allocate(1).put((byte) 1)));
    blockletIndex1.setMin_max_index(blockletMinMaxIndex);
    new MockUp<FileFactory>() {

        @SuppressWarnings("unused")
        @Mock
        public FileFactory.FileType getFileType(String path) {
            return FileFactory.FileType.LOCAL;
        }

        @SuppressWarnings("unused")
        @Mock
        public FileHolder getFileHolder(FileFactory.FileType fileType) {
            return new FileHolderImpl();
        }
    };
    new MockUp<FileHolderImpl>() {

        @SuppressWarnings("unused")
        @Mock
        public long readLong(String filePath, long offset) {
            return 1;
        }
    };
    new MockUp<CarbonFooterReader>() {

        @SuppressWarnings("unused")
        @Mock
        public FileFooter readFooter() throws IOException {
            return fileFooter;
        }
    };
    SegmentInfo segmentInfo = new SegmentInfo();
    int[] arr = { 1, 2, 3 };
    segmentInfo.setColumnCardinality(arr);
    segmentInfo.setNumberOfColumns(segmentInfo1.getNum_cols());
    dataFileFooter.setNumberOfRows(3);
    dataFileFooter.setSegmentInfo(segmentInfo);
    TableBlockInfo info = new TableBlockInfo("/file.carbondata", 1, "0", new String[0], 1, ColumnarFormatVersion.V1);
    DataFileFooter result = dataFileFooterConverter.readDataFileFooter(info);
    assertEquals(result.getNumberOfRows(), 3);
}
Also used : TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.format.ColumnSchema) MockUp(mockit.MockUp) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) org.apache.carbondata.format(org.apache.carbondata.format) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) SegmentInfo(org.apache.carbondata.core.metadata.blocklet.SegmentInfo) FileHolderImpl(org.apache.carbondata.core.datastore.impl.FileHolderImpl) Test(org.junit.Test)

Aggregations

DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)29 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 BlockletIndex (org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex)9 ByteBuffer (java.nio.ByteBuffer)8 BTreeBuilderInfo (org.apache.carbondata.core.datastore.BTreeBuilderInfo)8 BtreeBuilder (org.apache.carbondata.core.datastore.BtreeBuilder)8 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)8 TableBlockInfo (org.apache.carbondata.core.datastore.block.TableBlockInfo)7 DataRefNode (org.apache.carbondata.core.datastore.DataRefNode)6 KeyGenerator (org.apache.carbondata.core.keygenerator.KeyGenerator)6 MultiDimKeyVarLengthGenerator (org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator)6 BlockletInfo (org.apache.carbondata.core.metadata.blocklet.BlockletInfo)6 SegmentInfo (org.apache.carbondata.core.metadata.blocklet.SegmentInfo)6 DataRefNodeFinder (org.apache.carbondata.core.datastore.DataRefNodeFinder)5 IndexKey (org.apache.carbondata.core.datastore.IndexKey)5 HashMap (java.util.HashMap)3 MockUp (mockit.MockUp)3 KeyGenException (org.apache.carbondata.core.keygenerator.KeyGenException)3 BlockletBTreeIndex (org.apache.carbondata.core.metadata.blocklet.index.BlockletBTreeIndex)3