-
Notifications
You must be signed in to change notification settings - Fork 702
/
CompressedMeasureChunkFileBasedReaderV1.java
108 lines (99 loc) · 4.53 KB
/
CompressedMeasureChunkFileBasedReaderV1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.carbondata.core.datastore.chunk.reader.measure.v1;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import org.apache.carbondata.core.datastore.FileReader;
import org.apache.carbondata.core.datastore.chunk.impl.MeasureRawColumnChunk;
import org.apache.carbondata.core.datastore.chunk.reader.measure.AbstractMeasureChunkReader;
import org.apache.carbondata.core.datastore.compression.CompressorFactory;
import org.apache.carbondata.core.datastore.page.ColumnPage;
import org.apache.carbondata.core.datastore.page.encoding.ColumnPageDecoder;
import org.apache.carbondata.core.memory.MemoryException;
import org.apache.carbondata.core.metadata.ValueEncoderMeta;
import org.apache.carbondata.core.metadata.blocklet.BlockletInfo;
import org.apache.carbondata.core.metadata.blocklet.datachunk.DataChunk;
/**
* Compressed measure chunk reader
*/
public class CompressedMeasureChunkFileBasedReaderV1 extends AbstractMeasureChunkReader {
/**
* measure chunk have the information about the metadata present in the file
*/
private final List<DataChunk> measureColumnChunks;
/**
* Constructor to get minimum parameter to create instance of this class
*
* @param blockletInfo BlockletInfo
* @param filePath file from which data will be read
*/
public CompressedMeasureChunkFileBasedReaderV1(final BlockletInfo blockletInfo,
final String filePath) {
super(filePath, blockletInfo.getNumberOfRows());
this.measureColumnChunks = blockletInfo.getMeasureColumnChunk();
}
/**
* Method to read the blocks data based on block indexes
*
* @param fileReader file reader to read the blocks
* @param columnIndexRange blocks to be read
* @return measure data chunks
*/
@Override public MeasureRawColumnChunk[] readRawMeasureChunks(FileReader fileReader,
int[][] columnIndexRange) throws IOException {
MeasureRawColumnChunk[] datChunk = new MeasureRawColumnChunk[measureColumnChunks.size()];
for (int i = 0; i < columnIndexRange.length; i++) {
for (int j = columnIndexRange[i][0]; j <= columnIndexRange[i][1]; j++) {
datChunk[j] = readRawMeasureChunk(fileReader, j);
}
}
return datChunk;
}
/**
* Method to read the blocks data based on block index
*
* @param fileReader file reader to read the blocks
* @param columnIndex column to be read
* @return measure data chunk
*/
@Override public MeasureRawColumnChunk readRawMeasureChunk(FileReader fileReader, int columnIndex)
throws IOException {
DataChunk dataChunk = measureColumnChunks.get(columnIndex);
ByteBuffer buffer = fileReader
.readByteBuffer(filePath, dataChunk.getDataPageOffset(), dataChunk.getDataPageLength());
MeasureRawColumnChunk rawColumnChunk = new MeasureRawColumnChunk(columnIndex, buffer, 0,
dataChunk.getDataPageLength(), this);
rawColumnChunk.setFileReader(fileReader);
rawColumnChunk.setPagesCount(1);
rawColumnChunk.setRowCount(new int[] { numberOfRows });
return rawColumnChunk;
}
@Override
public ColumnPage decodeColumnPage(MeasureRawColumnChunk measureRawColumnChunk,
int pageNumber) throws IOException, MemoryException {
int blockIndex = measureRawColumnChunk.getColumnIndex();
DataChunk dataChunk = measureColumnChunks.get(blockIndex);
ValueEncoderMeta meta = dataChunk.getValueEncoderMeta().get(0);
ColumnPageDecoder codec = encodingFactory.createDecoderLegacy(meta,
CompressorFactory.NativeSupportedCompressor.SNAPPY.getName());
ColumnPage decodedPage = codec.decode(measureRawColumnChunk.getRawData().array(),
(int) measureRawColumnChunk.getOffSet(), dataChunk.getDataPageLength());
decodedPage.setNullBits(dataChunk.getNullValueIndexForColumn());
return decodedPage;
}
}