use of org.apache.carbondata.core.service.DictionaryService in project carbondata by apache.
the class IncrementalColumnDictionaryGenerator method writeDictionaryData.
@Override
public void writeDictionaryData(String tableUniqueName) throws IOException {
// initialize params
CarbonMetadata metadata = CarbonMetadata.getInstance();
CarbonTable carbonTable = metadata.getCarbonTable(tableUniqueName);
CarbonTableIdentifier tableIdentifier = carbonTable.getCarbonTableIdentifier();
ColumnIdentifier columnIdentifier = dimension.getColumnIdentifier();
String storePath = carbonTable.getStorePath();
DictionaryService dictionaryService = CarbonCommonFactory.getDictionaryService();
// create dictionary cache from dictionary File
DictionaryColumnUniqueIdentifier identifier = new DictionaryColumnUniqueIdentifier(tableIdentifier, columnIdentifier, columnIdentifier.getDataType());
Boolean isDictExists = CarbonUtil.isFileExistsForGivenColumn(storePath, identifier);
Dictionary dictionary = null;
long t1 = System.currentTimeMillis();
if (isDictExists) {
Cache<DictionaryColumnUniqueIdentifier, Dictionary> dictCache = CacheProvider.getInstance().createCache(CacheType.REVERSE_DICTIONARY, storePath);
dictionary = dictCache.get(identifier);
}
long dictCacheTime = System.currentTimeMillis() - t1;
long t2 = System.currentTimeMillis();
// write dictionary
CarbonDictionaryWriter dictionaryWriter = null;
dictionaryWriter = dictionaryService.getDictionaryWriter(tableIdentifier, columnIdentifier, storePath);
List<String> distinctValues = writeDictionary(dictionaryWriter, isDictExists);
long dictWriteTime = System.currentTimeMillis() - t2;
long t3 = System.currentTimeMillis();
// write sort index
if (distinctValues.size() > 0) {
writeSortIndex(distinctValues, dictionary, dictionaryService, tableIdentifier, columnIdentifier, storePath);
}
long sortIndexWriteTime = System.currentTimeMillis() - t3;
// update Meta Data
updateMetaData(dictionaryWriter);
LOGGER.audit("\n columnName: " + dimension.getColName() + "\n columnId: " + dimension.getColumnId() + "\n new distinct values count: " + distinctValues.size() + "\n create dictionary cache: " + dictCacheTime + "\n sort list, distinct and write: " + dictWriteTime + "\n write sort info: " + sortIndexWriteTime);
}
use of org.apache.carbondata.core.service.DictionaryService in project carbondata by apache.
the class AbstractDictionaryCache method readLastChunkFromDictionaryMetadataFile.
/**
* This method will read dictionary metadata file and return the dictionary meta chunks
*
* @param dictionaryColumnUniqueIdentifier
* @return list of dictionary metadata chunks
* @throws IOException read and close method throws IO exception
*/
protected CarbonDictionaryColumnMetaChunk readLastChunkFromDictionaryMetadataFile(DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) throws IOException {
DictionaryService dictService = CarbonCommonFactory.getDictionaryService();
CarbonDictionaryMetadataReader columnMetadataReaderImpl = dictService.getDictionaryMetadataReader(dictionaryColumnUniqueIdentifier);
CarbonDictionaryColumnMetaChunk carbonDictionaryColumnMetaChunk = null;
// read metadata file
try {
carbonDictionaryColumnMetaChunk = columnMetadataReaderImpl.readLastEntryOfDictionaryMetaChunk();
} finally {
// close the metadata reader
columnMetadataReaderImpl.close();
}
return carbonDictionaryColumnMetaChunk;
}
use of org.apache.carbondata.core.service.DictionaryService in project carbondata by apache.
the class AbstractDictionaryCache method getNumRecordsInCarbonDictionaryColumnMetaChunk.
/**
* get the dictionary column meta chunk for object already read and stored in LRU cache
* @param dictionaryColumnUniqueIdentifier
* @param offsetRead
* @return
* @throws IOException
*/
protected long getNumRecordsInCarbonDictionaryColumnMetaChunk(DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier, long offsetRead) throws IOException {
DictionaryService dictService = CarbonCommonFactory.getDictionaryService();
CarbonDictionaryMetadataReader columnMetadataReaderImpl = dictService.getDictionaryMetadataReader(dictionaryColumnUniqueIdentifier);
CarbonDictionaryColumnMetaChunk carbonDictionaryColumnMetaChunk = null;
// read metadata file
try {
carbonDictionaryColumnMetaChunk = columnMetadataReaderImpl.readEntryOfDictionaryMetaChunk(offsetRead);
} finally {
// close the metadata reader
columnMetadataReaderImpl.close();
}
return carbonDictionaryColumnMetaChunk.getMax_surrogate_key();
}
use of org.apache.carbondata.core.service.DictionaryService in project carbondata by apache.
the class IncrementalColumnDictionaryGenerator method writeDictionaryData.
@Override
public void writeDictionaryData() throws IOException {
// initialize params
AbsoluteTableIdentifier absoluteTableIdentifier = carbonTable.getAbsoluteTableIdentifier();
ColumnIdentifier columnIdentifier = dimension.getColumnIdentifier();
DictionaryService dictionaryService = CarbonCommonFactory.getDictionaryService();
// create dictionary cache from dictionary File
DictionaryColumnUniqueIdentifier identifier = new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier, columnIdentifier, columnIdentifier.getDataType());
Boolean isDictExists = CarbonUtil.isFileExistsForGivenColumn(identifier);
Dictionary dictionary = null;
long t1 = System.currentTimeMillis();
if (isDictExists) {
Cache<DictionaryColumnUniqueIdentifier, Dictionary> dictCache = CacheProvider.getInstance().createCache(CacheType.REVERSE_DICTIONARY);
dictionary = dictCache.get(identifier);
}
long dictCacheTime = System.currentTimeMillis() - t1;
long t2 = System.currentTimeMillis();
// write dictionary
CarbonDictionaryWriter dictionaryWriter = null;
dictionaryWriter = dictionaryService.getDictionaryWriter(identifier);
List<String> distinctValues = writeDictionary(dictionaryWriter, isDictExists);
long dictWriteTime = System.currentTimeMillis() - t2;
long t3 = System.currentTimeMillis();
// write sort index
if (distinctValues.size() > 0) {
writeSortIndex(distinctValues, dictionary, dictionaryService, absoluteTableIdentifier, columnIdentifier);
}
long sortIndexWriteTime = System.currentTimeMillis() - t3;
// update Meta Data
updateMetaData(dictionaryWriter);
LOGGER.audit("\n columnName: " + dimension.getColName() + "\n columnId: " + dimension.getColumnId() + "\n new distinct values count: " + distinctValues.size() + "\n create dictionary cache: " + dictCacheTime + "\n sort list, distinct and write: " + dictWriteTime + "\n write sort info: " + sortIndexWriteTime);
if (isDictExists) {
CarbonUtil.clearDictionaryCache(dictionary);
}
}
Aggregations