Search in sources :

Example 16 with LinearGutmanSplitStrategy

use of io.druid.collections.spatial.split.LinearGutmanSplitStrategy in project druid by druid-io.

the class ImmutableRTreeTest method testSearchWithSplitLimitedBoundRoaring.

@Test
public void testSearchWithSplitLimitedBoundRoaring() {
    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 = 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 : 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) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 17 with LinearGutmanSplitStrategy

use of io.druid.collections.spatial.split.LinearGutmanSplitStrategy in project druid by druid-io.

the class ImmutableRTreeTest method testToAndFromByteBufferRoaring.

@Test
public void testToAndFromByteBufferRoaring() {
    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, 1 }, 2);
    tree.insert(new float[] { 2, 2 }, 3);
    tree.insert(new float[] { 3, 3 }, 4);
    tree.insert(new float[] { 4, 4 }, 5);
    ImmutableRTree firstTree = ImmutableRTree.newImmutableFromMutable(tree);
    ByteBuffer buffer = ByteBuffer.wrap(firstTree.toBytes());
    ImmutableRTree secondTree = new ImmutableRTree(buffer, bf);
    Iterable<ImmutableBitmap> points = secondTree.search(new RadiusBound(new float[] { 0, 0 }, 10));
    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 : IntIterator(org.roaringbitmap.IntIterator) RadiusBound(io.druid.collections.spatial.search.RadiusBound) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 18 with LinearGutmanSplitStrategy

use of io.druid.collections.spatial.split.LinearGutmanSplitStrategy in project druid by druid-io.

the class ImmutableRTreeTest method testEmptyRoaringBitmap.

@Test
public void testEmptyRoaringBitmap() {
    BitmapFactory bf = new RoaringBitmapFactory();
    RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
    tree.insert(new float[] { 0.0f, 0.0f }, bf.makeEmptyMutableBitmap());
    ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
    Iterable<ImmutableBitmap> points = searchTree.search(new RadiusBound(new float[] { 0.0f, 0.0f }, 5));
    ImmutableBitmap finalSet = bf.union(points);
    Assert.assertEquals(finalSet.size(), 0);
    Assert.assertTrue(finalSet.isEmpty());
}
Also used : RadiusBound(io.druid.collections.spatial.search.RadiusBound) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 19 with LinearGutmanSplitStrategy

use of io.druid.collections.spatial.split.LinearGutmanSplitStrategy 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 = 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 : 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) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 20 with LinearGutmanSplitStrategy

use of io.druid.collections.spatial.split.LinearGutmanSplitStrategy in project druid by druid-io.

the class ImmutableRTreeTest method testSearchNoSplit.

@Test
public void testSearchNoSplit() {
    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[] { 10, 10 }, 10);
    tree.insert(new float[] { 1, 3 }, 2);
    tree.insert(new float[] { 27, 34 }, 20);
    tree.insert(new float[] { 106, 19 }, 30);
    tree.insert(new float[] { 4, 2 }, 3);
    tree.insert(new float[] { 5, 0 }, 4);
    tree.insert(new float[] { 4, 72 }, 40);
    tree.insert(new float[] { -4, -3 }, 5);
    tree.insert(new float[] { 119, -78 }, 50);
    Assert.assertEquals(tree.getRoot().getChildren().size(), 10);
    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) RadiusBound(io.druid.collections.spatial.search.RadiusBound) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) Test(org.junit.Test)

Aggregations

BitmapFactory (io.druid.collections.bitmap.BitmapFactory)21 LinearGutmanSplitStrategy (io.druid.collections.spatial.split.LinearGutmanSplitStrategy)21 ConciseBitmapFactory (io.druid.collections.bitmap.ConciseBitmapFactory)19 RoaringBitmapFactory (io.druid.collections.bitmap.RoaringBitmapFactory)19 ImmutableBitmap (io.druid.collections.bitmap.ImmutableBitmap)18 Test (org.junit.Test)16 IntIterator (org.roaringbitmap.IntIterator)14 RadiusBound (io.druid.collections.spatial.search.RadiusBound)13 Random (java.util.Random)12 RectangularBound (io.druid.collections.spatial.search.RectangularBound)3 Stopwatch (com.google.common.base.Stopwatch)2 ImmutableRTree (io.druid.collections.spatial.ImmutableRTree)2 RTree (io.druid.collections.spatial.RTree)2 BitmapSerdeFactory (io.druid.segment.data.BitmapSerdeFactory)2 IndexedRTree (io.druid.segment.data.IndexedRTree)2 Closeable (java.io.Closeable)2 ByteBuffer (java.nio.ByteBuffer)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 SerializerUtils (io.druid.common.utils.SerializerUtils)1 ISE (io.druid.java.util.common.ISE)1