use of org.apache.carbondata.core.cache.dictionary.Dictionary in project carbondata by apache.
the class VectorizedCarbonRecordReader method close.
@Override
public void close() throws IOException {
logStatistics(rowCount, queryModel.getStatisticsRecorder());
if (columnarBatch != null) {
columnarBatch.close();
columnarBatch = null;
}
// clear dictionary cache
Map<String, Dictionary> columnToDictionaryMapping = queryModel.getColumnToDictionaryMapping();
if (null != columnToDictionaryMapping) {
for (Map.Entry<String, Dictionary> entry : columnToDictionaryMapping.entrySet()) {
CarbonUtil.clearDictionaryCache(entry.getValue());
}
}
try {
queryExecutor.finish();
} catch (QueryExecutionException e) {
throw new IOException(e);
}
}
use of org.apache.carbondata.core.cache.dictionary.Dictionary in project carbondata by apache.
the class QueryUtil method getDictionaryMap.
/**
* Below method will be used to get the column id to its dictionary mapping
*
* @param dictionaryColumnIdList dictionary column list
* @param absoluteTableIdentifier absolute table identifier
* @return dictionary mapping
* @throws IOException
*/
private static Map<String, Dictionary> getDictionaryMap(List<String> dictionaryColumnIdList, AbsoluteTableIdentifier absoluteTableIdentifier) throws IOException {
// this for dictionary unique identifier
List<DictionaryColumnUniqueIdentifier> dictionaryColumnUniqueIdentifiers = getDictionaryColumnUniqueIdentifierList(dictionaryColumnIdList, absoluteTableIdentifier.getCarbonTableIdentifier());
CacheProvider cacheProvider = CacheProvider.getInstance();
Cache<DictionaryColumnUniqueIdentifier, Dictionary> forwardDictionaryCache = cacheProvider.createCache(CacheType.FORWARD_DICTIONARY, absoluteTableIdentifier.getStorePath());
List<Dictionary> columnDictionaryList = forwardDictionaryCache.getAll(dictionaryColumnUniqueIdentifiers);
Map<String, Dictionary> columnDictionaryMap = new HashMap<>(columnDictionaryList.size());
for (int i = 0; i < dictionaryColumnUniqueIdentifiers.size(); i++) {
// TODO: null check for column dictionary, if cache size is less it
// might return null here, in that case throw exception
columnDictionaryMap.put(dictionaryColumnIdList.get(i), columnDictionaryList.get(i));
}
return columnDictionaryMap;
}
use of org.apache.carbondata.core.cache.dictionary.Dictionary in project carbondata by apache.
the class CarbonDictionarySortInfoPreparatorTest method testGetDictionarySortInfo.
/**
* Tests the getDictionarySortInfo method
*/
@Test
public void testGetDictionarySortInfo() {
List<String> newDistinctValues = new ArrayList<>();
newDistinctValues.add("abc");
newDistinctValues.add("xyz");
Dictionary dictionary = new MockUp<Dictionary>() {
@Mock
public DictionaryChunksWrapper getDictionaryChunks() {
List<byte[]> data = new ArrayList<>();
data.add(new byte[] { 1, 2 });
List<List<byte[]>> dictionaryChunks = new ArrayList<>();
dictionaryChunks.add(data);
return new DictionaryChunksWrapper(dictionaryChunks);
}
}.getMockInstance();
new MockUp<DictionaryChunksWrapper>() {
@Mock
public int getSize() {
return 1;
}
};
CarbonDictionarySortInfo carbonDictionarySortInfo = carbonDictionarySortInfoPreparator.getDictionarySortInfo(newDistinctValues, dictionary, DataType.ARRAY);
int expectedGetSortIndexValue = 1;
int expectedGetSortInvertedIndexLength = 3;
int actualGetSortIndexValue = carbonDictionarySortInfo.getSortIndex().get(0);
int actualGetSortInvertedIndexLength = carbonDictionarySortInfo.getSortIndexInverted().size();
assertEquals(actualGetSortIndexValue, expectedGetSortIndexValue);
assertEquals(actualGetSortInvertedIndexLength, expectedGetSortInvertedIndexLength);
}
Aggregations