Skip to content

Commit

Permalink
Rename Ranges -> PackedValueRanges
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Aug 8, 2024
1 parent 3709e57 commit 10f77f4
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.index.mapper.NumberFieldMapper;
import org.opensearch.index.mapper.NumericPointEncoder;
import org.opensearch.search.optimization.filterrewrite.Ranges;
import org.opensearch.search.optimization.filterrewrite.PackedValueRanges;
import org.opensearch.search.optimization.filterrewrite.TreeTraversal;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
Expand Down Expand Up @@ -102,7 +102,7 @@ public static class treeState {

// multiRangesTraverse params
PointValues.PointTree pointTree;
Ranges ranges;
PackedValueRanges packedValueRanges;
BiConsumer<Integer, List<Integer>> collectRangeIDs;
int maxNumNonZeroRanges = Integer.MAX_VALUE;

Expand Down Expand Up @@ -136,7 +136,7 @@ public void setup() throws IOException {
uppers[i] = numericPointEncoder.encodePoint(i * bucketWidth);
}

ranges = new Ranges(lowers, uppers);
packedValueRanges = new PackedValueRanges(lowers, uppers);
}

@TearDown
Expand All @@ -154,7 +154,7 @@ public Map<Integer, List<Integer>> multiRangeTraverseTree(treeState state) throw

TreeTraversal.RangeAwareIntersectVisitor treeVisitor = new TreeTraversal.DocCollectRangeAwareIntersectVisitor(
state.pointTree,
state.ranges,
state.packedValueRanges,
state.maxNumNonZeroRanges,
(activeIndex, docID) -> {
if (mockIDCollect.containsKey(activeIndex)) {
Expand Down
2 changes: 1 addition & 1 deletion release-notes/opensearch.release-notes-2.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* Update github action gradle-check to use pull_request_target for accessing token (#3728) ([#3731](https://github.com/opensearch-project/opensearch/pull/3731))
* Add gradle check test for github workflows (#3717) ([#3723](https://github.com/opensearch-project/opensearch/pull/3723))
* Used set to make shell scripts more strict (#3278) ([#3344](https://github.com/opensearch-project/opensearch/pull/3344))
* Bootstrap should implement a denylist of Java versions (ranges) (#3164) ([#3292](https://github.com/opensearch-project/opensearch/pull/3292))
* Bootstrap should implement a denylist of Java versions (packedValueRanges) (#3164) ([#3292](https://github.com/opensearch-project/opensearch/pull/3292))
* Add Github Workflow to build and publish lucene snapshots. (#2906) ([#3038](https://github.com/opensearch-project/opensearch/pull/3038))
* Remove JavaVersion in favour of standard Runtime.Version (java-version-checker) (#3027) ([#3034](https://github.com/opensearch-project/opensearch/pull/3034))
* Remove JavaVersion, use builtin Runtime.Version to deal with runtime versions (#3006) ([#3013](https://github.com/opensearch-project/opensearch/pull/3013))
Expand Down
2 changes: 1 addition & 1 deletion release-notes/opensearch.release-notes-2.14.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- [Search Pipeline] Handle default pipeline for multiple indices ([#13276](https://github.com/opensearch-project/OpenSearch/pull/13276))
- [Batch Ingestion] Add `batch_size` to `_bulk` API. ([#12457](https://github.com/opensearch-project/OpenSearch/issues/12457))
- [Remote Store] Add capability of doing refresh as determined by the translog ([#12992](https://github.com/opensearch-project/OpenSearch/pull/12992))
- Support multi ranges traversal when doing date histogram rewrite optimization. ([#13317](https://github.com/opensearch-project/OpenSearch/pull/13317))
- Support multi packedValueRanges traversal when doing date histogram rewrite optimization. ([#13317](https://github.com/opensearch-project/OpenSearch/pull/13317))

### Dependencies
- Bump `org.apache.commons:commons-configuration2` from 2.10.0 to 2.10.1 ([#12896](https://github.com/opensearch-project/OpenSearch/pull/12896))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void prepareFromSegment(LeafReaderContext leaf) throws IOException {
optimizationContext.setRangesFromSegment(buildRanges(bounds));
}

private Ranges buildRanges(long[] bounds) {
private PackedValueRanges buildRanges(long[] bounds) {
bounds = processHardBounds(bounds);
if (bounds == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static long[] getBoundsWithRangeQuery(PointRangeQuery prq, String fieldN
* Creates the date ranges from date histo aggregations using its interval,
* and min/max boundaries
*/
static Ranges createRangesFromAgg(
static PackedValueRanges createRangesFromAgg(
final DateFieldMapper.DateFieldType fieldType,
final long interval,
final Rounding.Prepared preparedRounding,
Expand Down Expand Up @@ -208,6 +208,6 @@ static Ranges createRangesFromAgg(
uppers[i] = max;
}

return new Ranges(lowers, uppers);
return new PackedValueRanges(lowers, uppers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public final class OptimizationContext {
int maxAggRewriteFilters;
String shardId;

private Ranges ranges;
private Ranges rangesFromSegment;
private PackedValueRanges packedValueRanges;
private PackedValueRanges packedValueRangesFromSegment;

// debug info related fields
private int leaf;
Expand All @@ -70,9 +70,9 @@ public boolean canOptimize(final Object parent, SearchContext context) {
}

public void prepare() throws IOException {
assert ranges == null : "Ranges should only be built once at shard level, but they are already built";
assert packedValueRanges == null : "Ranges should only be built once at shard level, but they are already built";
aggregatorBridge.prepare();
if (ranges != null) {
if (packedValueRanges != null) {
preparedAtShardLevel = true;
}
}
Expand All @@ -81,17 +81,17 @@ public void prepareFromSegment(LeafReaderContext leaf) throws IOException {
aggregatorBridge.prepareFromSegment(leaf);
}

void setRanges(Ranges ranges) {
this.ranges = ranges;
void setRanges(PackedValueRanges packedValueRanges) {
this.packedValueRanges = packedValueRanges;
}

void setRangesFromSegment(Ranges ranges) {
this.rangesFromSegment = ranges;
void setRangesFromSegment(PackedValueRanges packedValueRanges) {
this.packedValueRangesFromSegment = packedValueRanges;
}

Ranges getRanges() {
if (rangesFromSegment != null) return rangesFromSegment;
return ranges;
PackedValueRanges getRanges() {
if (packedValueRangesFromSegment != null) return packedValueRangesFromSegment;
return packedValueRanges;
}

/**
Expand Down Expand Up @@ -130,34 +130,34 @@ public boolean tryOptimize(
return false;
}

Ranges ranges = tryBuildRangesFromSegment(leafCtx, segmentMatchAll);
if (ranges == null) return false;
PackedValueRanges packedValueRanges = tryBuildRangesFromSegment(leafCtx, segmentMatchAll);
if (packedValueRanges == null) return false;

aggregatorBridge.tryOptimize(values, incrementDocCount, sub);

optimizedSegments++;
logger.debug("Fast filter optimization applied to shard {} segment {}", shardId, leafCtx.ord);
logger.debug("crossed leaf nodes: {}, inner nodes: {}", leaf, inner);

rangesFromSegment = null;
packedValueRangesFromSegment = null;
return true;
}

/**
* Even when ranges cannot be built at shard level, we can still build ranges
* at segment level when it's functionally match-all at segment level
*/
private Ranges tryBuildRangesFromSegment(LeafReaderContext leafCtx, boolean segmentMatchAll) throws IOException {
private PackedValueRanges tryBuildRangesFromSegment(LeafReaderContext leafCtx, boolean segmentMatchAll) throws IOException {
if (!preparedAtShardLevel && !segmentMatchAll) {
return null;
}

if (ranges == null) { // not built at shard level but segment match all
if (packedValueRanges == null) { // not built at shard level but segment match all
logger.debug("Shard {} segment {} functionally match all documents. Build the fast filter", shardId, leafCtx.ord);
prepareFromSegment(leafCtx);
return rangesFromSegment;
return packedValueRangesFromSegment;
}
return ranges;
return packedValueRanges;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
/**
* Internal ranges representation for the filter rewrite optimization
*/
public final class Ranges {
public final class PackedValueRanges {
static ArrayUtil.ByteArrayComparator comparator;
byte[][] lowers; // inclusive
byte[][] uppers; // exclusive
int size;
int byteLen;

public Ranges(byte[][] lowers, byte[][] uppers) {
public PackedValueRanges(byte[][] lowers, byte[][] uppers) {
this.lowers = lowers;
this.uppers = uppers;
assert lowers.length == uppers.length;
Expand All @@ -42,11 +42,11 @@ public static boolean withinUpperBound(byte[] value, byte[] upperBound) {
}

public boolean withinLowerBound(byte[] value, int idx) {
return Ranges.withinLowerBound(value, lowers[idx]);
return PackedValueRanges.withinLowerBound(value, lowers[idx]);
}

public boolean withinUpperBound(byte[] value, int idx) {
return Ranges.withinUpperBound(value, uppers[idx]);
return PackedValueRanges.withinUpperBound(value, uppers[idx]);
}

public boolean withinRange(byte[] value, int idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void buildRanges(RangeAggregator.Range[] ranges) {
uppers[i] = upper;
}

optimizationContext.setRanges(new Ranges(lowers, uppers));
optimizationContext.setRanges(new PackedValueRanges(lowers, uppers));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ public static OptimizationContext.DebugInfo multiRangesTraverse(RangeAwareInters
*/
public static abstract class RangeAwareIntersectVisitor implements PointValues.IntersectVisitor {
private final PointValues.PointTree pointTree;
private final Ranges ranges;
private final PackedValueRanges packedValueRanges;
private final int maxNumNonZeroRange;
protected int visitedRange = 0;
protected int activeIndex;

public RangeAwareIntersectVisitor(PointValues.PointTree pointTree, Ranges ranges, int maxNumNonZeroRange) {
this.ranges = ranges;
public RangeAwareIntersectVisitor(PointValues.PointTree pointTree, PackedValueRanges packedValueRanges, int maxNumNonZeroRange) {
this.packedValueRanges = packedValueRanges;
this.pointTree = pointTree;
this.maxNumNonZeroRange = maxNumNonZeroRange;
this.activeIndex = ranges.firstRangeIndex(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
this.activeIndex = packedValueRanges.firstRangeIndex(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
}

public int getActiveIndex() {
Expand Down Expand Up @@ -121,17 +121,17 @@ public void traverse(OptimizationContext.DebugInfo debug) throws IOException {
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
// try to find the first range that may collect values from this cell
if (!ranges.withinUpperBound(minPackedValue, activeIndex) && iterateRangeEnd(minPackedValue)) {
if (!packedValueRanges.withinUpperBound(minPackedValue, activeIndex) && iterateRangeEnd(minPackedValue)) {
throw new CollectionTerminatedException();
}

// after the loop, min < upper
// cell could be outside [min max] lower
if (!ranges.withinLowerBound(maxPackedValue, activeIndex) && iterateRangeEnd(maxPackedValue)) {
if (!packedValueRanges.withinLowerBound(maxPackedValue, activeIndex) && iterateRangeEnd(maxPackedValue)) {
return PointValues.Relation.CELL_OUTSIDE_QUERY;
}

if (ranges.withinRange(minPackedValue, activeIndex) && ranges.withinRange(maxPackedValue, activeIndex)) {
if (packedValueRanges.withinRange(minPackedValue, activeIndex) && packedValueRanges.withinRange(maxPackedValue, activeIndex)) {
return PointValues.Relation.CELL_INSIDE_QUERY;
}
return PointValues.Relation.CELL_CROSSES_QUERY;
Expand All @@ -143,10 +143,10 @@ public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue
* @return true when packedValue falls within the activeIndex range
*/
protected boolean canCollect(byte[] packedValue) {
if (!ranges.withinUpperBound(packedValue, activeIndex) && iterateRangeEnd(packedValue)) {
if (!packedValueRanges.withinUpperBound(packedValue, activeIndex) && iterateRangeEnd(packedValue)) {
throw new CollectionTerminatedException();
}
return ranges.withinRange(packedValue, activeIndex);
return packedValueRanges.withinRange(packedValue, activeIndex);
}

/**
Expand All @@ -156,8 +156,8 @@ protected boolean canCollect(byte[] packedValue) {
protected boolean iterateRangeEnd(byte[] packedValue) {
// the new value may not be contiguous to the previous one
// so try to find the first next range that cross the new value
while (!ranges.withinUpperBound(packedValue, activeIndex)) {
if (++activeIndex >= ranges.size) {
while (!packedValueRanges.withinUpperBound(packedValue, activeIndex)) {
if (++activeIndex >= packedValueRanges.size) {
return true;
}
}
Expand All @@ -176,11 +176,11 @@ public static class DocCountRangeAwareIntersectVisitor extends RangeAwareInterse

public DocCountRangeAwareIntersectVisitor(
PointValues.PointTree pointTree,
Ranges ranges,
PackedValueRanges packedValueRanges,
int maxNumNonZeroRange,
BiConsumer<Integer, Integer> countDocs
) {
super(pointTree, ranges, maxNumNonZeroRange);
super(pointTree, packedValueRanges, maxNumNonZeroRange);
this.countDocs = countDocs;
}

Expand Down Expand Up @@ -223,11 +223,11 @@ public static class DocCollectRangeAwareIntersectVisitor extends RangeAwareInter

public DocCollectRangeAwareIntersectVisitor(
PointValues.PointTree pointTree,
Ranges ranges,
PackedValueRanges packedValueRanges,
int maxNumNonZeroRange,
BiConsumer<Integer, Integer> collectDocs
) {
super(pointTree, ranges, maxNumNonZeroRange);
super(pointTree, packedValueRanges, maxNumNonZeroRange);
this.collectDocs = collectDocs;
}

Expand Down

0 comments on commit 10f77f4

Please sign in to comment.