Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ private RowRangeIndex(List<Range> ranges) {
}
}

/** Builds an index from a bitmap, skipping sorting and merging for already ordered ranges. */
public static RowRangeIndex fromBitmap(RoaringNavigableMap64 bitmap) {
List<Range> ranges = bitmap.toRangeList();
// Bitmap order is unsigned; mixed signs still require signed sorting and merging.
if (ranges.size() > 1 && ranges.get(0).from > ranges.get(ranges.size() - 1).from) {
return create(ranges);
}
return new RowRangeIndex(ranges);
}

public static RowRangeIndex create(List<Range> ranges) {
return create(ranges, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,52 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.stream.LongStream;

import static org.assertj.core.api.Assertions.assertThat;

/** Tests for {@link RowRangeIndex}. */
class RowRangeIndexTest {

@Test
void testFromBitmapPreservesRangeQueriesAndOwnership() {
for (long[] values :
new long[][] {
{},
{0},
{0, 1, 2, 9, 11, 12},
{Integer.MAX_VALUE, (1L << 32) - 1, 1L << 32, Long.MAX_VALUE},
{-2, -1, 0, 1, Long.MAX_VALUE},
{Long.MIN_VALUE, -2, -1},
LongStream.range(0, 10000).toArray()
}) {
RoaringNavigableMap64 bitmap = RoaringNavigableMap64.bitmapOf(values);
RowRangeIndex expected = RowRangeIndex.create(bitmap.toRangeList());
RowRangeIndex actual = RowRangeIndex.fromBitmap(bitmap);
assertThat(actual.ranges()).isEqualTo(expected.ranges());
long[] bounds = {
Long.MIN_VALUE, -2, -1, 0, 1, 3, 8, 9, 10, 11, 13, 9999, 1L << 32, Long.MAX_VALUE
};
for (long start : bounds) {
for (long end : bounds) {
if (start <= end) {
Range range = new Range(start, end);
assertThat(actual.intersects(start, end))
.isEqualTo(expected.intersects(start, end));
assertThat(actual.intersectedRanges(start, end))
.isEqualTo(expected.intersectedRanges(start, end));
assertThat(actual.contains(range)).isEqualTo(expected.contains(range));
assertThat(actual.containsExactly(range))
.isEqualTo(expected.containsExactly(range));
}
}
}
bitmap.add(20000);
assertThat(actual.ranges()).isEqualTo(expected.ranges());
assertThat(actual.intersects(20000, 20000)).isFalse();
}
}

@Test
void testContains() {
RowRangeIndex index =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public Plan plan() {
}
if (indexResult.isPresent()) {
GlobalIndexResult result = indexResult.get();
rowRangeIndex = RowRangeIndex.create(result.results().toRangeList());
rowRangeIndex = RowRangeIndex.fromBitmap(result.results());
if (result instanceof ScoredGlobalIndexResult) {
scoreGetter = ((ScoredGlobalIndexResult) result).scoreGetter();
}
Expand Down
Loading