Search in sources :

Example 11 with ConciseBitmapFactory

use of io.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 QuadraticGutmanSplitStrategy(0, 100, bf), bf);
    RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
    Random rand = new Random();
    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 = Sets.newHashSet();
    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(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) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Test(org.junit.Test)

Example 12 with ConciseBitmapFactory

use of io.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(io.druid.collections.bitmap.ConciseBitmapFactory) 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)

Example 13 with ConciseBitmapFactory

use of io.druid.collections.bitmap.ConciseBitmapFactory 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)

Example 14 with ConciseBitmapFactory

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

the class LinearGutmanSplitStrategyTest method testPickSeeds.

@Test
public void testPickSeeds() throws Exception {
    BitmapFactory bf = new ConciseBitmapFactory();
    LinearGutmanSplitStrategy strategy = new LinearGutmanSplitStrategy(0, 50, bf);
    Node node = new Node(new float[2], new float[2], true, bf);
    node.addChild(new Point(new float[] { 3, 7 }, 1, bf));
    node.addChild(new Point(new float[] { 1, 6 }, 1, bf));
    node.addChild(new Point(new float[] { 9, 8 }, 1, bf));
    node.addChild(new Point(new float[] { 2, 5 }, 1, bf));
    node.addChild(new Point(new float[] { 4, 4 }, 1, bf));
    node.enclose();
    Node[] groups = strategy.split(node);
    Assert.assertEquals(groups[0].getMinCoordinates()[0], 1.0f);
    Assert.assertEquals(groups[0].getMinCoordinates()[1], 4.0f);
    Assert.assertEquals(groups[1].getMinCoordinates()[0], 9.0f);
    Assert.assertEquals(groups[1].getMinCoordinates()[1], 8.0f);
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) Node(io.druid.collections.spatial.Node) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Point(io.druid.collections.spatial.Point) Test(org.junit.Test)

Example 15 with ConciseBitmapFactory

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

the class LinearGutmanSplitStrategyTest method testNumChildrenSize.

@Test
public void testNumChildrenSize() {
    BitmapFactory bf = new ConciseBitmapFactory();
    RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
    Random rand = new Random();
    for (int i = 0; i < 100; i++) {
        tree.insert(new float[] { rand.nextFloat(), rand.nextFloat() }, i);
    }
    Assert.assertTrue(getNumPoints(tree.getRoot()) >= tree.getSize());
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) Random(java.util.Random) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) RTree(io.druid.collections.spatial.RTree) Point(io.druid.collections.spatial.Point) 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