use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class ImmutableRTreeTest method testSearchWithSplitRoaring.
@Test
public void testSearchWithSplitRoaring() {
BitmapFactory bf = new RoaringBitmapFactory();
RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
tree.insert(new float[] { 0, 0 }, 1);
tree.insert(new float[] { 1, 3 }, 2);
tree.insert(new float[] { 4, 2 }, 3);
tree.insert(new float[] { 5, 0 }, 4);
tree.insert(new float[] { -4, -3 }, 5);
Random rand = ThreadLocalRandom.current();
for (int i = 0; i < 95; i++) {
tree.insert(new float[] { (float) (rand.nextDouble() * 10 + 10.0), (float) (rand.nextDouble() * 10 + 10.0) }, i);
}
ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
Iterable<ImmutableBitmap> points = searchTree.search(new RadiusBound(new float[] { 0, 0 }, 5));
ImmutableBitmap finalSet = bf.union(points);
Assert.assertTrue(finalSet.size() >= 5);
Set<Integer> expected = Sets.newHashSet(1, 2, 3, 4, 5);
IntIterator iter = finalSet.iterator();
while (iter.hasNext()) {
Assert.assertTrue(expected.contains(iter.next()));
}
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class ImmutableRTreeTest method testSearchWithSplit2.
@Test
public void testSearchWithSplit2() {
BitmapFactory bf = new ConciseBitmapFactory();
RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
tree.insert(new float[] { 0.0f, 0.0f }, 0);
tree.insert(new float[] { 1.0f, 3.0f }, 1);
tree.insert(new float[] { 4.0f, 2.0f }, 2);
tree.insert(new float[] { 7.0f, 3.0f }, 3);
tree.insert(new float[] { 8.0f, 6.0f }, 4);
Random rand = ThreadLocalRandom.current();
for (int i = 5; i < 5000; i++) {
tree.insert(new float[] { (float) (rand.nextDouble() * 10 + 10.0), (float) (rand.nextDouble() * 10 + 10.0) }, i);
}
ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
Iterable<ImmutableBitmap> points = searchTree.search(new RectangularBound(new float[] { 0, 0 }, new float[] { 9, 9 }));
ImmutableBitmap finalSet = bf.union(points);
Assert.assertTrue(finalSet.size() >= 5);
Set<Integer> expected = Sets.newHashSet(0, 1, 2, 3, 4);
IntIterator iter = finalSet.iterator();
while (iter.hasNext()) {
Assert.assertTrue(expected.contains(iter.next()));
}
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class ImmutableRTreeTest method showBenchmarks.
// TODO rewrite to JMH and move to the benchmarks project
@SuppressWarnings("unused")
public void showBenchmarks() {
final int start = 1;
final int factor = 10;
final int end = 10000000;
final int radius = 10;
for (int numPoints = start; numPoints <= end; numPoints *= factor) {
try {
BitmapFactory bf = new ConciseBitmapFactory();
RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
Stopwatch stopwatch = Stopwatch.createStarted();
Random rand = ThreadLocalRandom.current();
for (int i = 0; i < numPoints; i++) {
tree.insert(new float[] { (float) (rand.nextDouble() * 100), (float) (rand.nextDouble() * 100) }, i);
}
long stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
System.out.printf(Locale.ENGLISH, "[%,d]: insert = %,d ms%n", numPoints, stop);
stopwatch.reset().start();
ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
System.out.printf(Locale.ENGLISH, "[%,d]: size = %,d bytes%n", numPoints, searchTree.toBytes().length);
System.out.printf(Locale.ENGLISH, "[%,d]: buildImmutable = %,d ms%n", numPoints, stop);
stopwatch.reset().start();
Iterable<ImmutableBitmap> points = searchTree.search(new RadiusBound(new float[] { 50, 50 }, radius));
Iterables.size(points);
stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
System.out.printf(Locale.ENGLISH, "[%,d]: search = %,dms%n", numPoints, stop);
stopwatch.reset().start();
ImmutableBitmap finalSet = bf.union(points);
stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
System.out.printf(Locale.ENGLISH, "[%,d]: union of %,d points in %,d ms%n", numPoints, finalSet.size(), stop);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class AndFilter method makeMatcher.
@Override
public ValueMatcher makeMatcher(BitmapIndexSelector selector, ColumnSelectorFactory columnSelectorFactory, RowOffsetMatcherFactory rowOffsetMatcherFactory) {
final List<ValueMatcher> matchers = new ArrayList<>();
final List<ImmutableBitmap> bitmaps = new ArrayList<>();
for (Filter filter : filters) {
if (filter.supportsBitmapIndex(selector)) {
bitmaps.add(filter.getBitmapIndex(selector));
} else {
ValueMatcher matcher = filter.makeMatcher(columnSelectorFactory);
matchers.add(matcher);
}
}
if (bitmaps.size() > 0) {
ImmutableBitmap combinedBitmap = selector.getBitmapFactory().intersection(bitmaps);
ValueMatcher offsetMatcher = rowOffsetMatcherFactory.makeRowOffsetMatcher(combinedBitmap);
matchers.add(0, offsetMatcher);
}
return makeMatcher(matchers.toArray(BooleanFilter.EMPTY_VALUE_MATCHER_ARRAY));
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class BoundFilterBenchmark method matchNothingLexicographic.
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void matchNothingLexicographic() {
final ImmutableBitmap bitmapIndex = NOTHING_LEXICOGRAPHIC.getBitmapIndex(selector);
Preconditions.checkState(bitmapIndex.size() == 0);
}
Aggregations