Search in sources :

Example 16 with ConciseBitmapFactory

use of org.apache.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(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IntIterator(org.roaringbitmap.IntIterator) 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 17 with ConciseBitmapFactory

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

the class ImmutableRTreeTest method showBenchmarksBoundWithLimits.

// TODO rewrite to JMH and move to the benchmarks project
@SuppressWarnings("unused")
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 = 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 RectangularBound(new float[] { 40, 40 }, new float[] { 60, 60 }, 100));
            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);
        }
    }
}
Also used : ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) Stopwatch(com.google.common.base.Stopwatch) LinearGutmanSplitStrategy(org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy) RectangularBound(org.apache.druid.collections.spatial.search.RectangularBound) 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)

Example 18 with ConciseBitmapFactory

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

the class EmptyIndexTest method testEmptyIndex.

@Test
public void testEmptyIndex() throws Exception {
    File tmpDir = File.createTempFile("emptyIndex", "");
    if (!tmpDir.delete()) {
        throw new IllegalStateException("tmp delete failed");
    }
    if (!tmpDir.mkdir()) {
        throw new IllegalStateException("tmp mkdir failed");
    }
    try {
        IncrementalIndex emptyIndex = new OnheapIncrementalIndex.Builder().setSimpleTestingIndexSchema().setMaxRowCount(1000).build();
        IncrementalIndexAdapter emptyIndexAdapter = new IncrementalIndexAdapter(Intervals.of("2012-08-01/P3D"), emptyIndex, new ConciseBitmapFactory());
        TestHelper.getTestIndexMergerV9(segmentWriteOutMediumFactory).merge(Collections.singletonList(emptyIndexAdapter), true, new AggregatorFactory[0], tmpDir, new IndexSpec(), -1);
        QueryableIndex emptyQueryableIndex = TestHelper.getTestIndexIO().loadIndex(tmpDir);
        Assert.assertEquals("getDimensionNames", 0, Iterables.size(emptyQueryableIndex.getAvailableDimensions()));
        Assert.assertEquals("getMetricNames", 0, emptyQueryableIndex.getColumnNames().size());
        Assert.assertEquals("getDataInterval", Intervals.of("2012-08-01/P3D"), emptyQueryableIndex.getDataInterval());
        Assert.assertEquals("getReadOnlyTimestamps", 0, emptyQueryableIndex.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME).getLength());
    } finally {
        FileUtils.deleteDirectory(tmpDir);
    }
}
Also used : IncrementalIndexAdapter(org.apache.druid.segment.incremental.IncrementalIndexAdapter) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) OnheapIncrementalIndex(org.apache.druid.segment.incremental.OnheapIncrementalIndex) OnheapIncrementalIndex(org.apache.druid.segment.incremental.OnheapIncrementalIndex) File(java.io.File) 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