Search in sources :

Example 1 with DefaultEncodingFactory

use of org.apache.carbondata.core.datastore.page.encoding.DefaultEncodingFactory in project carbondata by apache.

the class CarbonTestUtil method validateDictionary.

public static Boolean validateDictionary(DimensionRawColumnChunk rawColumnPage, String[] data) throws IOException {
    LocalDictionaryChunk local_dictionary = rawColumnPage.getDataChunkV3().local_dictionary;
    if (null != local_dictionary) {
        String compressorName = CarbonMetadataUtil.getCompressorNameFromChunkMeta(rawColumnPage.getDataChunkV3().getData_chunk_list().get(0).getChunk_meta());
        List<org.apache.carbondata.format.Encoding> encodings = local_dictionary.getDictionary_meta().encoders;
        DefaultEncodingFactory encodingFactory = (DefaultEncodingFactory) DefaultEncodingFactory.getInstance();
        ColumnPageDecoder decoder = encodingFactory.createDecoder(encodings, local_dictionary.getDictionary_meta().getEncoder_meta(), compressorName);
        LazyColumnPage dictionaryPage = (LazyColumnPage) decoder.decode(local_dictionary.getDictionary_data(), 0, local_dictionary.getDictionary_data().length);
        HashMap<DictionaryByteArrayWrapper, Integer> dictionaryMap = new HashMap<>();
        BitSet usedDictionaryValues = BitSet.valueOf(CompressorFactory.getInstance().getCompressor(compressorName).unCompressByte(local_dictionary.getDictionary_values()));
        int index = 0;
        int i = usedDictionaryValues.nextSetBit(0);
        while (i >= 0) {
            dictionaryMap.put(new DictionaryByteArrayWrapper(dictionaryPage.getBytes(index)), i);
            i = usedDictionaryValues.nextSetBit(i + 1);
            index += 1;
        }
        for (i = 0; i < data.length; i++) {
            if (null == dictionaryMap.get(new DictionaryByteArrayWrapper(data[i].getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET))))) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : DictionaryByteArrayWrapper(org.apache.carbondata.core.cache.dictionary.DictionaryByteArrayWrapper) LocalDictionaryChunk(org.apache.carbondata.format.LocalDictionaryChunk) DefaultEncodingFactory(org.apache.carbondata.core.datastore.page.encoding.DefaultEncodingFactory) HashMap(java.util.HashMap) BitSet(java.util.BitSet) ColumnPageDecoder(org.apache.carbondata.core.datastore.page.encoding.ColumnPageDecoder) LazyColumnPage(org.apache.carbondata.core.datastore.page.LazyColumnPage)

Aggregations

BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 DictionaryByteArrayWrapper (org.apache.carbondata.core.cache.dictionary.DictionaryByteArrayWrapper)1 LazyColumnPage (org.apache.carbondata.core.datastore.page.LazyColumnPage)1 ColumnPageDecoder (org.apache.carbondata.core.datastore.page.encoding.ColumnPageDecoder)1 DefaultEncodingFactory (org.apache.carbondata.core.datastore.page.encoding.DefaultEncodingFactory)1 LocalDictionaryChunk (org.apache.carbondata.format.LocalDictionaryChunk)1