use of com.linkedin.pinot.core.segment.index.readers.IntDictionary in project pinot by linkedin.
the class ColumnMinMaxValueGenerator method addColumnMinMaxValueForColumn.
private void addColumnMinMaxValueForColumn(String columnName) throws Exception {
// Skip column without dictionary or with min/max value already set
ColumnMetadata columnMetadata = _segmentMetadata.getColumnMetadataFor(columnName);
if ((!columnMetadata.hasDictionary()) || (columnMetadata.getMinValue() != null)) {
return;
}
PinotDataBuffer dictionaryBuffer = _segmentWriter.getIndexFor(columnName, ColumnIndexType.DICTIONARY);
FieldSpec.DataType dataType = columnMetadata.getDataType();
switch(dataType) {
case INT:
IntDictionary intDictionary = new IntDictionary(dictionaryBuffer, columnMetadata);
SegmentColumnarIndexCreator.addColumnMinMaxValueInfo(_segmentProperties, columnName, intDictionary.getStringValue(0), intDictionary.getStringValue(intDictionary.length() - 1));
break;
case LONG:
LongDictionary longDictionary = new LongDictionary(dictionaryBuffer, columnMetadata);
SegmentColumnarIndexCreator.addColumnMinMaxValueInfo(_segmentProperties, columnName, longDictionary.getStringValue(0), longDictionary.getStringValue(longDictionary.length() - 1));
break;
case FLOAT:
FloatDictionary floatDictionary = new FloatDictionary(dictionaryBuffer, columnMetadata);
SegmentColumnarIndexCreator.addColumnMinMaxValueInfo(_segmentProperties, columnName, floatDictionary.getStringValue(0), floatDictionary.getStringValue(floatDictionary.length() - 1));
break;
case DOUBLE:
DoubleDictionary doubleDictionary = new DoubleDictionary(dictionaryBuffer, columnMetadata);
SegmentColumnarIndexCreator.addColumnMinMaxValueInfo(_segmentProperties, columnName, doubleDictionary.getStringValue(0), doubleDictionary.getStringValue(doubleDictionary.length() - 1));
break;
case STRING:
StringDictionary stringDictionary = new StringDictionary(dictionaryBuffer, columnMetadata);
SegmentColumnarIndexCreator.addColumnMinMaxValueInfo(_segmentProperties, columnName, stringDictionary.get(0), stringDictionary.get(stringDictionary.length() - 1));
break;
default:
throw new IllegalStateException("Unsupported data type: " + dataType + " for column: " + columnName);
}
_minMaxValueAdded = true;
}
use of com.linkedin.pinot.core.segment.index.readers.IntDictionary in project pinot by linkedin.
the class BitmapPerformanceBenchmark method benchmarkIntersetionAndUnion.
public static void benchmarkIntersetionAndUnion(String indexSegmentDir) throws ConfigurationException, IOException, Exception {
File[] listFiles = new File(indexSegmentDir).listFiles();
File indexDir = new File(indexSegmentDir);
SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(indexDir);
Map<String, BitmapInvertedIndexReader> bitMapIndexMap = new HashMap<String, BitmapInvertedIndexReader>();
Map<String, Integer> cardinalityMap = new HashMap<String, Integer>();
Map<String, ImmutableDictionaryReader> dictionaryMap = new HashMap<String, ImmutableDictionaryReader>();
for (File file : listFiles) {
if (!file.getName().endsWith("bitmap.inv")) {
continue;
}
String column = file.getName().replaceAll(".bitmap.inv", "");
ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(column);
int cardinality = columnMetadata.getCardinality();
cardinalityMap.put(column, cardinality);
System.out.println(column + "\t\t\t" + cardinality + " \t" + columnMetadata.getDataType());
PinotDataBuffer bitmapDataBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "testing");
BitmapInvertedIndexReader bitmapInvertedIndex = new BitmapInvertedIndexReader(bitmapDataBuffer, cardinality);
File dictionaryFile = new File(indexSegmentDir + "/" + column + ".dict");
SegmentDirectory segmentDirectory = SegmentDirectory.createFromLocalFS(indexDir, segmentMetadata, ReadMode.mmap);
SegmentDirectory.Reader segmentReader = segmentDirectory.createReader();
ColumnIndexContainer container = ColumnIndexContainer.init(segmentReader, columnMetadata, null);
ImmutableDictionaryReader dictionary = container.getDictionary();
if (columnMetadata.getDataType() == DataType.INT) {
System.out.println("BitmapPerformanceBenchmark.main()");
assert dictionary instanceof IntDictionary;
}
dictionaryMap.put(column, dictionary);
// System.out.println(column + ":\t" + MemoryUtil.deepMemoryUsageOf(bitmapInvertedIndex));
bitMapIndexMap.put(column, bitmapInvertedIndex);
bitmapDataBuffer.close();
}
List<String> dimensionNamesList = segmentMetadata.getSchema().getDimensionNames();
Collections.shuffle(dimensionNamesList);
int NUM_TEST = 100;
final int MAX_DIMENSIONS_PER_DIMENSION = 1;
int MAX_DIMENSIONS_IN_WHERE_CLAUSE = 3;
Random random = new Random();
for (int numDimensions = 1; numDimensions <= MAX_DIMENSIONS_IN_WHERE_CLAUSE; numDimensions++) {
for (int numValuesPerDimension = 1; numValuesPerDimension <= MAX_DIMENSIONS_PER_DIMENSION; numValuesPerDimension++) {
int runCount = 0;
while (runCount < NUM_TEST) {
Collections.shuffle(dimensionNamesList);
List<ImmutableRoaringBitmap> bitMaps = new ArrayList<ImmutableRoaringBitmap>();
List<String> columnNameValuePairs = new ArrayList<String>();
for (int i = 0; i < numDimensions; i++) {
String columnName = dimensionNamesList.get(i);
InvertedIndexReader bitmapInvertedIndex = bitMapIndexMap.get(columnName);
for (int j = 0; j < numValuesPerDimension; j++) {
int dictId = random.nextInt(cardinalityMap.get(columnName));
String dictValue = dictionaryMap.get(columnName).getStringValue(dictId);
columnNameValuePairs.add(columnName + ":" + dictValue);
ImmutableRoaringBitmap immutable = bitmapInvertedIndex.getImmutable(dictId);
bitMaps.add(immutable);
}
}
System.out.println("START**********************************");
int[] cardinality = new int[bitMaps.size()];
int[] sizes = new int[bitMaps.size()];
for (int i = 0; i < bitMaps.size(); i++) {
ImmutableRoaringBitmap immutableRoaringBitmap = bitMaps.get(i);
cardinality[i] = immutableRoaringBitmap.getCardinality();
sizes[i] = immutableRoaringBitmap.getSizeInBytes();
}
System.out.println("\t#bitmaps:" + bitMaps.size());
System.out.println("\tinput values:" + columnNameValuePairs);
System.out.println("\tinput cardinality:" + Arrays.toString(cardinality));
System.out.println("\tinput sizes:" + Arrays.toString(sizes));
and(bitMaps);
or(bitMaps);
System.out.println("END**********************************");
runCount = runCount + 1;
}
}
}
}
use of com.linkedin.pinot.core.segment.index.readers.IntDictionary in project pinot by linkedin.
the class DictionariesTest method test1.
@Test
public void test1() throws Exception {
final IndexSegmentImpl heapSegment = (IndexSegmentImpl) ColumnarSegmentLoader.load(segmentDirectory, ReadMode.heap);
final IndexSegmentImpl mmapSegment = (IndexSegmentImpl) ColumnarSegmentLoader.load(segmentDirectory, ReadMode.mmap);
for (final String column : ((SegmentMetadataImpl) mmapSegment.getSegmentMetadata()).getColumnMetadataMap().keySet()) {
final ImmutableDictionaryReader heapDictionary = heapSegment.getDictionaryFor(column);
final ImmutableDictionaryReader mmapDictionary = mmapSegment.getDictionaryFor(column);
switch(((SegmentMetadataImpl) mmapSegment.getSegmentMetadata()).getColumnMetadataMap().get(column).getDataType()) {
case BOOLEAN:
case STRING:
Assert.assertTrue(heapDictionary instanceof StringDictionary);
Assert.assertTrue(mmapDictionary instanceof StringDictionary);
break;
case DOUBLE:
Assert.assertTrue(heapDictionary instanceof DoubleDictionary);
Assert.assertTrue(mmapDictionary instanceof DoubleDictionary);
break;
case FLOAT:
Assert.assertTrue(heapDictionary instanceof FloatDictionary);
Assert.assertTrue(mmapDictionary instanceof FloatDictionary);
break;
case LONG:
Assert.assertTrue(heapDictionary instanceof LongDictionary);
Assert.assertTrue(mmapDictionary instanceof LongDictionary);
break;
case INT:
Assert.assertTrue(heapDictionary instanceof IntDictionary);
Assert.assertTrue(mmapDictionary instanceof IntDictionary);
break;
}
Assert.assertEquals(mmapDictionary.length(), heapDictionary.length());
for (int i = 0; i < heapDictionary.length(); i++) {
Assert.assertEquals(mmapDictionary.get(i), heapDictionary.get(i));
}
}
}
Aggregations