use of com.linkedin.pinot.core.common.BlockMetadata in project pinot by linkedin.
the class BitmapDocIdSetTest method testSimple.
@Test
public void testSimple() throws IOException {
int numBitMaps = 5;
final int numDocs = 1000;
List<ImmutableRoaringBitmap> list = new ArrayList<ImmutableRoaringBitmap>();
Random r = new Random();
TreeSet<Integer> originalSet = new TreeSet<Integer>();
for (int i = 0; i < numBitMaps; i++) {
MutableRoaringBitmap mutableRoaringBitmap = new MutableRoaringBitmap();
int length = r.nextInt(numDocs);
for (int j = 0; j < length; j++) {
int docId = r.nextInt(numDocs);
originalSet.add(docId);
mutableRoaringBitmap.add(docId);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
// could call "rr1.runOptimize()" and "rr2.runOptimize" if there
// there were runs to compress
mutableRoaringBitmap.serialize(dos);
dos.close();
ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
ImmutableRoaringBitmap immutableRoaringBitmap = new ImmutableRoaringBitmap(bb);
list.add(immutableRoaringBitmap);
}
ImmutableRoaringBitmap[] bitmaps = new ImmutableRoaringBitmap[list.size()];
list.toArray(bitmaps);
BlockMetadata blockMetadata = new BlockMetadata() {
@Override
public boolean isSparse() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSorted() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSingleValue() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasInvertedIndex() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasDictionary() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getStartDocId() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getMaxNumberOfMultiValues() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getLength() {
return numDocs;
}
@Override
public int getEndDocId() {
return numDocs - 1;
}
@Override
public Dictionary getDictionary() {
// TODO Auto-generated method stub
return null;
}
@Override
public DataType getDataType() {
// TODO Auto-generated method stub
return null;
}
};
BitmapDocIdSet bitmapDocIdSet = new BitmapDocIdSet("testColumn", blockMetadata, 0, numDocs - 1, bitmaps);
BlockDocIdIterator iterator = bitmapDocIdSet.iterator();
int docId;
TreeSet<Integer> result = new TreeSet<Integer>();
while ((docId = iterator.next()) != Constants.EOF) {
result.add(docId);
}
Assert.assertEquals(originalSet.size(), result.size());
Assert.assertEquals(originalSet, result);
}
Aggregations