use of com.linkedin.pinot.core.segment.creator.impl.inv.HeapBitmapInvertedIndexCreator in project pinot by linkedin.
the class BitmapInvertedIndexCreatorTest method testSingleValue.
@Test
public void testSingleValue() throws IOException {
boolean singleValue = true;
String colName = "single_value_col";
FieldSpec spec = new DimensionFieldSpec(colName, DataType.INT, singleValue);
int numDocs = 20;
int[] data = new int[numDocs];
int cardinality = 10;
File indexDirHeap = new File("/tmp/indexDirHeap");
FileUtils.forceMkdir(indexDirHeap);
indexDirHeap.mkdirs();
File indexDirOffHeap = new File("/tmp/indexDirOffHeap");
FileUtils.forceMkdir(indexDirOffHeap);
indexDirOffHeap.mkdirs();
File bitmapIndexFileOffHeap = new File(indexDirOffHeap, colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);
File bitmapIndexFileHeap = new File(indexDirHeap, colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);
// GENERATE RANDOM DATA SET
Random r = new Random();
Map<Integer, Set<Integer>> postingListMap = new HashMap<>();
for (int i = 0; i < cardinality; i++) {
postingListMap.put(i, new LinkedHashSet<Integer>());
}
for (int i = 0; i < numDocs; i++) {
data[i] = r.nextInt(cardinality);
LOGGER.debug("docId:" + i + " dictId:" + data[i]);
postingListMap.get(data[i]).add(i);
}
for (int i = 0; i < cardinality; i++) {
LOGGER.debug("Posting list for " + i + " : " + postingListMap.get(i));
}
// GENERATE BITMAP USING OffHeapCreator and validate
OffHeapBitmapInvertedIndexCreator offHeapCreator = new OffHeapBitmapInvertedIndexCreator(indexDirOffHeap, cardinality, numDocs, numDocs, spec);
for (int i = 0; i < numDocs; i++) {
offHeapCreator.add(i, data[i]);
}
offHeapCreator.seal();
validate(colName, bitmapIndexFileOffHeap, cardinality, postingListMap);
// GENERATE BITMAP USING HeapCreator and validate
HeapBitmapInvertedIndexCreator heapCreator = new HeapBitmapInvertedIndexCreator(indexDirHeap, cardinality, numDocs, 0, spec);
for (int i = 0; i < numDocs; i++) {
heapCreator.add(i, data[i]);
}
heapCreator.seal();
validate(colName, bitmapIndexFileHeap, cardinality, postingListMap);
// assert that the file sizes and contents are the same
Assert.assertEquals(bitmapIndexFileHeap.length(), bitmapIndexFileHeap.length());
Assert.assertTrue(FileUtils.contentEquals(bitmapIndexFileHeap, bitmapIndexFileHeap));
FileUtils.deleteQuietly(indexDirHeap);
FileUtils.deleteQuietly(indexDirOffHeap);
}
use of com.linkedin.pinot.core.segment.creator.impl.inv.HeapBitmapInvertedIndexCreator in project pinot by linkedin.
the class BitmapInvertedIndexCreatorTest method testMultiValue.
@Test
public void testMultiValue() throws IOException {
boolean singleValue = false;
String colName = "multi_value_col";
FieldSpec spec = new DimensionFieldSpec(colName, DataType.INT, singleValue);
int numDocs = 20;
int[][] data = new int[numDocs][];
int maxLength = 10;
int cardinality = 10;
File indexDirHeap = new File("/tmp/indexDirHeap");
FileUtils.forceMkdir(indexDirHeap);
indexDirHeap.mkdirs();
File indexDirOffHeap = new File("/tmp/indexDirOffHeap");
FileUtils.forceMkdir(indexDirOffHeap);
indexDirOffHeap.mkdirs();
File bitmapIndexFileOffHeap = new File(indexDirOffHeap, colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);
File bitmapIndexFileHeap = new File(indexDirHeap, colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);
// GENERATE RANDOM MULTI VALUE DATA SET
Random r = new Random();
Map<Integer, Set<Integer>> postingListMap = new HashMap<>();
for (int i = 0; i < cardinality; i++) {
postingListMap.put(i, new LinkedHashSet<Integer>());
}
int totalNumberOfEntries = 0;
for (int docId = 0; docId < numDocs; docId++) {
int length = r.nextInt(maxLength);
data[docId] = new int[length];
totalNumberOfEntries += length;
for (int j = 0; j < length; j++) {
data[docId][j] = r.nextInt(cardinality);
postingListMap.get(data[docId][j]).add(docId);
}
LOGGER.debug("docId:" + docId + " dictId:" + data[docId]);
}
for (int i = 0; i < cardinality; i++) {
LOGGER.debug("Posting list for " + i + " : " + postingListMap.get(i));
}
// GENERATE BITMAP USING OffHeapCreator and validate
OffHeapBitmapInvertedIndexCreator offHeapCreator = new OffHeapBitmapInvertedIndexCreator(indexDirOffHeap, cardinality, numDocs, totalNumberOfEntries, spec);
for (int i = 0; i < numDocs; i++) {
offHeapCreator.add(i, data[i]);
}
offHeapCreator.seal();
validate(colName, bitmapIndexFileOffHeap, cardinality, postingListMap);
// GENERATE BITMAP USING HeapCreator and validate
HeapBitmapInvertedIndexCreator heapCreator = new HeapBitmapInvertedIndexCreator(indexDirHeap, cardinality, numDocs, totalNumberOfEntries, spec);
for (int i = 0; i < numDocs; i++) {
heapCreator.add(i, data[i]);
}
heapCreator.seal();
validate(colName, bitmapIndexFileHeap, cardinality, postingListMap);
// assert that the file sizes and contents are the same
Assert.assertEquals(bitmapIndexFileHeap.length(), bitmapIndexFileHeap.length());
Assert.assertTrue(FileUtils.contentEquals(bitmapIndexFileHeap, bitmapIndexFileHeap));
FileUtils.deleteQuietly(indexDirHeap);
FileUtils.deleteQuietly(indexDirOffHeap);
}
Aggregations