Search in sources :

Example 1 with LinearGutmanSplitStrategy

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

the class StringDimensionMergerLegacy method writeIndexes.

@Override
public void writeIndexes(List<IntBuffer> segmentRowNumConversions, Closer closer) throws IOException {
    final SerializerUtils serializerUtils = new SerializerUtils();
    long dimStartTime = System.currentTimeMillis();
    final BitmapSerdeFactory bitmapSerdeFactory = indexSpec.getBitmapSerdeFactory();
    String bmpFilename = String.format("%s.inverted", dimensionName);
    bitmapWriter = new GenericIndexedWriter<>(ioPeon, bmpFilename, bitmapSerdeFactory.getObjectStrategy());
    bitmapWriter.open();
    final MappedByteBuffer dimValsMapped = Files.map(dictionaryFile);
    closer.register(new Closeable() {

        @Override
        public void close() throws IOException {
            ByteBufferUtils.unmap(dimValsMapped);
        }
    });
    if (!dimensionName.equals(serializerUtils.readString(dimValsMapped))) {
        throw new ISE("dimensions[%s] didn't equate!?  This is a major WTF moment.", dimensionName);
    }
    Indexed<String> dimVals = GenericIndexed.read(dimValsMapped, GenericIndexed.STRING_STRATEGY);
    log.info("Starting dimension[%s] with cardinality[%,d]", dimensionName, dimVals.size());
    final BitmapFactory bmpFactory = bitmapSerdeFactory.getBitmapFactory();
    RTree tree = null;
    spatialWriter = null;
    boolean hasSpatial = capabilities.hasSpatialIndexes();
    if (hasSpatial) {
        String spatialFilename = String.format("%s.spatial", dimensionName);
        spatialWriter = new ByteBufferWriter<>(ioPeon, spatialFilename, new IndexedRTree.ImmutableRTreeObjectStrategy(bmpFactory));
        spatialWriter.open();
        tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bmpFactory), bmpFactory);
    }
    IndexSeeker[] dictIdSeeker = toIndexSeekers(adapters, dimConversions, dimensionName);
    //Iterate all dim values's dictionary id in ascending order which in line with dim values's compare result.
    for (int dictId = 0; dictId < dimVals.size(); dictId++) {
        progress.progress();
        mergeBitmaps(segmentRowNumConversions, dimVals, bmpFactory, tree, hasSpatial, dictIdSeeker, dictId, adapters, dimensionName, nullRowsBitmap, bitmapWriter);
    }
    log.info("Completed dimension[%s] in %,d millis.", dimensionName, System.currentTimeMillis() - dimStartTime);
    if (hasSpatial) {
        spatialWriter.write(ImmutableRTree.newImmutableFromMutable(tree));
    }
}
Also used : Closeable(java.io.Closeable) IOException(java.io.IOException) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) MappedByteBuffer(java.nio.MappedByteBuffer) ISE(io.druid.java.util.common.ISE) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) ImmutableRTree(io.druid.collections.spatial.ImmutableRTree) IndexedRTree(io.druid.segment.data.IndexedRTree) RTree(io.druid.collections.spatial.RTree) BitmapSerdeFactory(io.druid.segment.data.BitmapSerdeFactory) SerializerUtils(io.druid.common.utils.SerializerUtils)

Example 2 with LinearGutmanSplitStrategy

use of io.druid.collections.spatial.split.LinearGutmanSplitStrategy 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 = new Random();
    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(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 3 with LinearGutmanSplitStrategy

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

the class ImmutableRTreeTest method testToAndFromByteBuffer.

@Test
public void testToAndFromByteBuffer() {
    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, 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 : 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) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with LinearGutmanSplitStrategy

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

the class ImmutableRTreeTest method testSearchWithSplit3Roaring.

@Test
public void testSearchWithSplit3Roaring() {
    BitmapFactory bf = new RoaringBitmapFactory();
    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.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 : 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 5 with LinearGutmanSplitStrategy

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

the class RTreeTest method setUp.

@Before
public void setUp() throws Exception {
    BitmapFactory bf = new ConciseBitmapFactory();
    tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
    BitmapFactory rbf = new RoaringBitmapFactory();
    roaringtree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, rbf), rbf);
}
Also used : ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(io.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Before(org.junit.Before)

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