Search in sources :

Example 6 with ConciseBitmapFactory

use of io.druid.collections.bitmap.ConciseBitmapFactory in project druid by druid-io.

the class ImmutableRTreeTest method showBenchmarks.

//@Test
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 = new Random();
            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("[%,d]: insert = %,d ms%n", numPoints, stop);
            stopwatch.reset().start();
            ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
            stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
            System.out.printf("[%,d]: size = %,d bytes%n", numPoints, searchTree.toBytes().length);
            System.out.printf("[%,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("[%,d]: search = %,dms%n", numPoints, stop);
            stopwatch.reset().start();
            ImmutableBitmap finalSet = bf.union(points);
            stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
            System.out.printf("[%,d]: union of %,d points in %,d ms%n", numPoints, finalSet.size(), stop);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) Stopwatch(com.google.common.base.Stopwatch) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) Random(java.util.Random) RadiusBound(io.druid.collections.spatial.search.RadiusBound) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory)

Example 7 with ConciseBitmapFactory

use of io.druid.collections.bitmap.ConciseBitmapFactory in project druid by druid-io.

the class ImmutableRTreeTest method showBenchmarksBoundWithLimits.

//@Test
public void showBenchmarksBoundWithLimits() {
    //final int start = 1;
    final int start = 10000000;
    final int factor = 10;
    final int end = 10000000;
    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 = new Random();
            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("[%,d]: insert = %,d ms%n", numPoints, stop);
            stopwatch.reset().start();
            ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
            stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
            System.out.printf("[%,d]: size = %,d bytes%n", numPoints, searchTree.toBytes().length);
            System.out.printf("[%,d]: buildImmutable = %,d ms%n", numPoints, stop);
            stopwatch.reset().start();
            Iterable<ImmutableBitmap> points = searchTree.search(new RectangularBound(new float[] { 40, 40 }, new float[] { 60, 60 }, 100));
            Iterables.size(points);
            stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
            System.out.printf("[%,d]: search = %,dms%n", numPoints, stop);
            stopwatch.reset().start();
            ImmutableBitmap finalSet = bf.union(points);
            stop = stopwatch.elapsed(TimeUnit.MILLISECONDS);
            System.out.printf("[%,d]: union of %,d points in %,d ms%n", numPoints, finalSet.size(), stop);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) Stopwatch(com.google.common.base.Stopwatch) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) RectangularBound(io.druid.collections.spatial.search.RectangularBound) Random(java.util.Random) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory)

Example 8 with ConciseBitmapFactory

use of io.druid.collections.bitmap.ConciseBitmapFactory in project druid by druid-io.

the class ImmutableRTreeTest method testSearchWithSplitLimitedBound.

@Test
public void testSearchWithSplitLimitedBound() {
    BitmapFactory bf = new ConciseBitmapFactory();
    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 = new Random();
    for (int i = 0; i < 4995; 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, 2));
    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()));
    }
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) Random(java.util.Random) RadiusBound(io.druid.collections.spatial.search.RadiusBound) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 9 with ConciseBitmapFactory

use of io.druid.collections.bitmap.ConciseBitmapFactory 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 = new Random();
    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()));
    }
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) RectangularBound(io.druid.collections.spatial.search.RectangularBound) Random(java.util.Random) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 10 with ConciseBitmapFactory

use of io.druid.collections.bitmap.ConciseBitmapFactory in project druid by druid-io.

the class ImmutableRTreeTest method testSearchWithSplit.

@Test
public void testSearchWithSplit() {
    BitmapFactory bf = new ConciseBitmapFactory();
    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 = new Random();
    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()));
    }
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) Random(java.util.Random) RadiusBound(io.druid.collections.spatial.search.RadiusBound) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Aggregations

ConciseBitmapFactory (io.druid.collections.bitmap.ConciseBitmapFactory)15 BitmapFactory (io.druid.collections.bitmap.BitmapFactory)14 RoaringBitmapFactory (io.druid.collections.bitmap.RoaringBitmapFactory)14 ImmutableBitmap (io.druid.collections.bitmap.ImmutableBitmap)11 LinearGutmanSplitStrategy (io.druid.collections.spatial.split.LinearGutmanSplitStrategy)11 Test (org.junit.Test)11 Random (java.util.Random)8 IntIterator (org.roaringbitmap.IntIterator)8 RadiusBound (io.druid.collections.spatial.search.RadiusBound)7 Stopwatch (com.google.common.base.Stopwatch)2 Point (io.druid.collections.spatial.Point)2 RectangularBound (io.druid.collections.spatial.search.RectangularBound)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Node (io.druid.collections.spatial.Node)1 RTree (io.druid.collections.spatial.RTree)1 Json (io.druid.guice.annotations.Json)1 ISE (io.druid.java.util.common.ISE)1 BitmapIndex (io.druid.segment.column.BitmapIndex)1 Column (io.druid.segment.column.Column)1