Search in sources :

Example 1 with FileHolderImpl

use of org.apache.carbondata.core.datastore.impl.FileHolderImpl 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)

Example 2 with FileHolderImpl

use of org.apache.carbondata.core.datastore.impl.FileHolderImpl in project carbondata by apache.

the class FileHolderImplUnitTest method setup.

@BeforeClass
public static void setup() {
    fileHolder = new FileHolderImpl();
    fileHolderWithCapacity = new FileHolderImpl(50);
    file = new File("Test.carbondata");
    fileWithEmptyContent = new File("TestEXception.carbondata");
    if (!file.exists())
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    if (!fileWithEmptyContent.exists())
        try {
            fileWithEmptyContent.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    try {
        FileOutputStream of = new FileOutputStream(file, true);
        BufferedWriter br = new BufferedWriter(new OutputStreamWriter(of, "UTF-8"));
        br.write("Hello World");
        br.close();
    } catch (Exception e) {
        e.getMessage();
    }
    fileName = file.getAbsolutePath();
    fileNameWithEmptyContent = fileWithEmptyContent.getAbsolutePath();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileHolderImpl(org.apache.carbondata.core.datastore.impl.FileHolderImpl) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

FileHolderImpl (org.apache.carbondata.core.datastore.impl.FileHolderImpl)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 MockUp (mockit.MockUp)1 TableBlockInfo (org.apache.carbondata.core.datastore.block.TableBlockInfo)1 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)1 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)1 SegmentInfo (org.apache.carbondata.core.metadata.blocklet.SegmentInfo)1 org.apache.carbondata.format (org.apache.carbondata.format)1 ColumnSchema (org.apache.carbondata.format.ColumnSchema)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1