/** * This method will check and create columnReverseDictionaryInfo object for the given column * * @param dictionaryColumnUniqueIdentifier * @param columnIdentifier * @return */ private ColumnReverseDictionaryInfo getColumnReverseDictionaryInfo( DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier, String columnIdentifier) { ColumnReverseDictionaryInfo columnReverseDictionaryInfo = (ColumnReverseDictionaryInfo) carbonLRUCache .get(getLruCacheKey(columnIdentifier, CacheType.REVERSE_DICTIONARY)); if (null == columnReverseDictionaryInfo) { synchronized (dictionaryColumnUniqueIdentifier) { columnReverseDictionaryInfo = (ColumnReverseDictionaryInfo) carbonLRUCache .get(getLruCacheKey(columnIdentifier, CacheType.REVERSE_DICTIONARY)); if (null == columnReverseDictionaryInfo) { columnReverseDictionaryInfo = new ColumnReverseDictionaryInfo(); } } } return columnReverseDictionaryInfo; }
/** * This method will remove the cache for a given key * * @param dictionaryColumnUniqueIdentifier unique identifier which contains dbName, * tableName and columnIdentifier */ @Override public void invalidate( DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) { carbonLRUCache.remove( getLruCacheKey(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(), CacheType.REVERSE_DICTIONARY)); }
@Override public void clearAccessCount(List<DictionaryColumnUniqueIdentifier> keys) { for (DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier : keys) { Dictionary cacheable = (Dictionary) carbonLRUCache.get( getLruCacheKey(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(), CacheType.REVERSE_DICTIONARY)); cacheable.clear(); } }
/** * This method will return the value for the given key. It will not check and load * the data for the given key * * @param dictionaryColumnUniqueIdentifier unique identifier which contains dbName, * tableName and columnIdentifier * @return */ @Override public Dictionary getIfPresent( DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) { Dictionary reverseDictionary = null; ColumnReverseDictionaryInfo columnReverseDictionaryInfo = (ColumnReverseDictionaryInfo) carbonLRUCache.get( getLruCacheKey(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(), CacheType.REVERSE_DICTIONARY)); if (null != columnReverseDictionaryInfo) { reverseDictionary = new ReverseDictionary(columnReverseDictionaryInfo); incrementDictionaryAccessCount(columnReverseDictionaryInfo); } return reverseDictionary; }
/** * This method will get the value for the given key. If value does not exist * for the given key, it will check and load the value. * * @param dictionaryColumnUniqueIdentifier unique identifier which contains dbName, * tableName and columnIdentifier * @return dictionary * @throws IOException in case memory is not sufficient to load dictionary into memory */ private Dictionary getDictionary( DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) throws IOException { Dictionary reverseDictionary = null; // dictionary is only for primitive data type assert (!dictionaryColumnUniqueIdentifier.getDataType().isComplexType()); String columnIdentifier = dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(); ColumnReverseDictionaryInfo columnReverseDictionaryInfo = getColumnReverseDictionaryInfo(dictionaryColumnUniqueIdentifier, columnIdentifier); // do not load sort index file for reverse dictionary checkAndLoadDictionaryData(dictionaryColumnUniqueIdentifier, columnReverseDictionaryInfo, getLruCacheKey(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId(), CacheType.REVERSE_DICTIONARY), false); reverseDictionary = new ReverseDictionary(columnReverseDictionaryInfo); return reverseDictionary; }