Search in sources :

Example 11 with ConciseBitmapFactory

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

the class ImmutableRTreeTest method testEmptyConciseSet.

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

Example 12 with ConciseBitmapFactory

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

the class ImmutableRTreeTest method testSearchWithSplit4.

@Test
public void testSearchWithSplit4() {
    BitmapFactory bf = new ConciseBitmapFactory();
    RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
    Random rand = ThreadLocalRandom.current();
    int outPolygon = 0, inPolygon = 0;
    for (; inPolygon < 500; ) {
        double abscissa = rand.nextDouble() * 5;
        double ordinate = rand.nextDouble() * 4;
        if (abscissa < 1 || abscissa > 4 || ordinate < 1 || ordinate > 3 || abscissa < 2 && ordinate > 2) {
            tree.insert(new float[] { (float) abscissa, (float) ordinate }, outPolygon + 500);
            outPolygon++;
        } else if (abscissa > 1 && abscissa < 4 && ordinate > 1 && ordinate < 2 || abscissa > 2 && abscissa < 4 && ordinate >= 2 && ordinate < 3) {
            tree.insert(new float[] { (float) abscissa, (float) ordinate }, inPolygon);
            inPolygon++;
        }
    }
    ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
    Iterable<ImmutableBitmap> points = searchTree.search(PolygonBound.from(new float[] { 1.0f, 1.0f, 2.0f, 2.0f, 4.0f, 4.0f }, new float[] { 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 1.0f }));
    ImmutableBitmap finalSet = bf.union(points);
    Assert.assertTrue(finalSet.size() == 500);
    Set<Integer> expected = new HashSet<>();
    for (int i = 0; i < 500; i++) {
        expected.add(i);
    }
    IntIterator iter = finalSet.iterator();
    while (iter.hasNext()) {
        Assert.assertTrue(expected.contains(iter.next()));
    }
}
Also used : ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) LinearGutmanSplitStrategy(org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ConciseBitmapFactory

use of org.apache.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 = ThreadLocalRandom.current();
    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(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) LinearGutmanSplitStrategy(org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RadiusBound(org.apache.druid.collections.spatial.search.RadiusBound) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 14 with ConciseBitmapFactory

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

the class ImmutableRTreeTest method testSearchWithSplit3.

@Test
public void testSearchWithSplit3() {
    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.nextFloat() * 10 + 10.0), (float) (rand.nextFloat() * 10 + 10.0) }, i);
    }
    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.assertTrue(finalSet.size() >= 3);
    Set<Integer> expected = Sets.newHashSet(0, 1, 2);
    IntIterator iter = finalSet.iterator();
    while (iter.hasNext()) {
        Assert.assertTrue(expected.contains(iter.next()));
    }
}
Also used : ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) LinearGutmanSplitStrategy(org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RadiusBound(org.apache.druid.collections.spatial.search.RadiusBound) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 15 with ConciseBitmapFactory

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

Aggregations

ConciseBitmapFactory (org.apache.druid.collections.bitmap.ConciseBitmapFactory)18 RoaringBitmapFactory (org.apache.druid.collections.bitmap.RoaringBitmapFactory)17 BitmapFactory (org.apache.druid.collections.bitmap.BitmapFactory)16 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)13 LinearGutmanSplitStrategy (org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy)11 Test (org.junit.Test)11 Random (java.util.Random)10 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 IntIterator (org.roaringbitmap.IntIterator)8 RadiusBound (org.apache.druid.collections.spatial.search.RadiusBound)7 IOException (java.io.IOException)3 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)3 IAE (org.apache.druid.java.util.common.IAE)3 Setup (org.openjdk.jmh.annotations.Setup)3 Stopwatch (com.google.common.base.Stopwatch)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Point (org.apache.druid.collections.spatial.Point)2 RectangularBound (org.apache.druid.collections.spatial.search.RectangularBound)2