use of io.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 = 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()));
}
}
use of io.druid.collections.bitmap.ConciseBitmapFactory 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()));
}
}
use of io.druid.collections.bitmap.ConciseBitmapFactory 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);
}
use of io.druid.collections.bitmap.ConciseBitmapFactory in project druid by druid-io.
the class DumpSegment method runBitmaps.
private void runBitmaps(final Injector injector, final QueryableIndex index) throws IOException {
final ObjectMapper objectMapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
final BitmapFactory bitmapFactory = index.getBitmapFactoryForDimensions();
final BitmapSerdeFactory bitmapSerdeFactory;
if (bitmapFactory instanceof ConciseBitmapFactory) {
bitmapSerdeFactory = new ConciseBitmapSerdeFactory();
} else if (bitmapFactory instanceof RoaringBitmapFactory) {
bitmapSerdeFactory = new RoaringBitmapSerdeFactory(null);
} else {
throw new ISE("Don't know which BitmapSerdeFactory to use for BitmapFactory[%s]!", bitmapFactory.getClass().getName());
}
final List<String> columnNames = getColumnsToInclude(index);
withOutputStream(new Function<OutputStream, Object>() {
@Override
public Object apply(final OutputStream out) {
try {
final JsonGenerator jg = objectMapper.getFactory().createGenerator(out);
jg.writeStartObject();
jg.writeObjectField("bitmapSerdeFactory", bitmapSerdeFactory);
jg.writeFieldName("bitmaps");
jg.writeStartObject();
for (final String columnName : columnNames) {
final Column column = index.getColumn(columnName);
final BitmapIndex bitmapIndex = column.getBitmapIndex();
if (bitmapIndex == null) {
jg.writeNullField(columnName);
} else {
jg.writeFieldName(columnName);
jg.writeStartObject();
for (int i = 0; i < bitmapIndex.getCardinality(); i++) {
jg.writeFieldName(Strings.nullToEmpty(bitmapIndex.getValue(i)));
final ImmutableBitmap bitmap = bitmapIndex.getBitmap(i);
if (decompressBitmaps) {
jg.writeStartArray();
final IntIterator iterator = bitmap.iterator();
while (iterator.hasNext()) {
final int rowNum = iterator.next();
jg.writeNumber(rowNum);
}
jg.writeEndArray();
} else {
jg.writeBinary(bitmapSerdeFactory.getObjectStrategy().toBytes(bitmap));
}
}
jg.writeEndObject();
}
}
jg.writeEndObject();
jg.writeEndObject();
jg.close();
} catch (IOException e) {
throw Throwables.propagate(e);
}
return null;
}
});
}
use of io.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(0, Granularities.NONE, new AggregatorFactory[0], 1000);
IncrementalIndexAdapter emptyIndexAdapter = new IncrementalIndexAdapter(new Interval("2012-08-01/P3D"), emptyIndex, new ConciseBitmapFactory());
TestHelper.getTestIndexMerger().merge(Lists.<IndexableAdapter>newArrayList(emptyIndexAdapter), true, new AggregatorFactory[0], tmpDir, new IndexSpec());
QueryableIndex emptyQueryableIndex = TestHelper.getTestIndexIO().loadIndex(tmpDir);
Assert.assertEquals("getDimensionNames", 0, Iterables.size(emptyQueryableIndex.getAvailableDimensions()));
Assert.assertEquals("getMetricNames", 0, Iterables.size(emptyQueryableIndex.getColumnNames()));
Assert.assertEquals("getDataInterval", new Interval("2012-08-01/P3D"), emptyQueryableIndex.getDataInterval());
Assert.assertEquals("getReadOnlyTimestamps", 0, emptyQueryableIndex.getColumn(Column.TIME_COLUMN_NAME).getLength());
} finally {
FileUtils.deleteDirectory(tmpDir);
}
}
Aggregations