Search in sources :

Example 1 with CarbonDictionaryImpl

use of org.apache.carbondata.core.scan.result.vector.impl.CarbonDictionaryImpl in project carbondata by apache.

the class DimensionRawColumnChunk method getDictionary.

/**
 * Below method will be used to get the local dictionary for a blocklet
 * @param localDictionaryChunk
 * local dictionary chunk thrift object
 * @return local dictionary
 * @throws IOException
 */
public static CarbonDictionary getDictionary(LocalDictionaryChunk localDictionaryChunk, Compressor compressor) throws IOException {
    if (null != localDictionaryChunk) {
        List<Encoding> encodings = localDictionaryChunk.getDictionary_meta().getEncoders();
        List<ByteBuffer> encoderMetas = localDictionaryChunk.getDictionary_meta().getEncoder_meta();
        ColumnPageDecoder decoder = DefaultEncodingFactory.getInstance().createDecoder(encodings, encoderMetas, compressor.getName());
        ColumnPage decode = decoder.decode(localDictionaryChunk.getDictionary_data(), 0, localDictionaryChunk.getDictionary_data().length);
        BitSet usedDictionary = BitSet.valueOf(compressor.unCompressByte(localDictionaryChunk.getDictionary_values()));
        int length = usedDictionary.length();
        int index = 0;
        byte[][] dictionary = new byte[length][];
        for (int i = 0; i < length; i++) {
            if (usedDictionary.get(i)) {
                dictionary[i] = decode.getBytes(index++);
            } else {
                dictionary[i] = null;
            }
        }
        decode.freeMemory();
        if (!usedDictionary.isEmpty()) {
            // as dictionary values starts from 1 setting null default value
            dictionary[1] = CarbonCommonConstants.MEMBER_DEFAULT_VAL_ARRAY;
        }
        return new CarbonDictionaryImpl(dictionary, usedDictionary.cardinality());
    }
    return null;
}
Also used : CarbonDictionaryImpl(org.apache.carbondata.core.scan.result.vector.impl.CarbonDictionaryImpl) DimensionColumnPage(org.apache.carbondata.core.datastore.chunk.DimensionColumnPage) ColumnPage(org.apache.carbondata.core.datastore.page.ColumnPage) BitSet(java.util.BitSet) Encoding(org.apache.carbondata.format.Encoding) ColumnPageDecoder(org.apache.carbondata.core.datastore.page.encoding.ColumnPageDecoder) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 BitSet (java.util.BitSet)1 DimensionColumnPage (org.apache.carbondata.core.datastore.chunk.DimensionColumnPage)1 ColumnPage (org.apache.carbondata.core.datastore.page.ColumnPage)1 ColumnPageDecoder (org.apache.carbondata.core.datastore.page.encoding.ColumnPageDecoder)1 CarbonDictionaryImpl (org.apache.carbondata.core.scan.result.vector.impl.CarbonDictionaryImpl)1 Encoding (org.apache.carbondata.format.Encoding)1