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;
}
Aggregations