From ba89da58cfcf1661cfd819c062b497be342cc968 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Thu, 8 Aug 2024 18:01:25 -0700 Subject: [PATCH] Replace generic object lambda in range agg with long primitive Signed-off-by: Finn Carroll --- .../bucket/composite/CompositeAggregator.java | 3 ++- .../bucket/histogram/AutoDateHistogramAggregator.java | 3 ++- .../bucket/histogram/DateHistogramAggregator.java | 3 ++- .../aggregations/bucket/range/RangeAggregator.java | 3 ++- .../optimization/filterrewrite/AggregatorBridge.java | 7 +++++++ .../filterrewrite/DateHistogramAggregatorBridge.java | 5 ----- .../filterrewrite/RangeAggregatorBridge.java | 9 ++------- .../search/optimization/filterrewrite/TreeTraversal.java | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java index 9ca27a3459ecf..c1efd0a20fbea 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/CompositeAggregator.java @@ -90,6 +90,7 @@ import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; +import java.util.function.LongFunction; import java.util.function.LongUnaryOperator; import java.util.stream.Collectors; @@ -219,7 +220,7 @@ protected int getSize() { } @Override - protected Function bucketOrdProducer() { + protected LongFunction bucketOrdProducer() { return (key) -> bucketOrds.add(0, getRoundingPrepared().round((long) key)); } }); diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java index dd6a4be8fbf7b..44ab5e35fac9d 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java @@ -66,6 +66,7 @@ import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; +import java.util.function.LongFunction; import java.util.function.LongToIntFunction; import static org.opensearch.search.optimization.filterrewrite.DateHistogramAggregatorBridge.segmentMatchAll; @@ -200,7 +201,7 @@ protected Prepared getRoundingPrepared() { } @Override - protected Function bucketOrdProducer() { + protected LongFunction bucketOrdProducer() { return (key) -> getBucketOrds().add(0, preparedRounding.round((long) key)); } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java index 3be7646518dc4..5c15794432a2c 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java @@ -60,6 +60,7 @@ import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; +import java.util.function.LongFunction; import static org.opensearch.search.optimization.filterrewrite.DateHistogramAggregatorBridge.segmentMatchAll; @@ -146,7 +147,7 @@ protected long[] processHardBounds(long[] bounds) { } @Override - protected Function bucketOrdProducer() { + protected LongFunction bucketOrdProducer() { return (key) -> bucketOrds.add(0, preparedRounding.round((long) key)); } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/range/RangeAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/range/RangeAggregator.java index 312ba60dcfb83..3161a5cfbfd59 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/range/RangeAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/range/RangeAggregator.java @@ -68,6 +68,7 @@ import java.util.Objects; import java.util.function.BiConsumer; import java.util.function.Function; +import java.util.function.LongFunction; import static org.opensearch.core.xcontent.ConstructingObjectParser.optionalConstructorArg; @@ -293,7 +294,7 @@ public void prepare() { } @Override - protected Function bucketOrdProducer() { + protected LongFunction bucketOrdProducer() { return (activeIndex) -> subBucketOrdinal(0, (int) activeIndex); } }); diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/AggregatorBridge.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/AggregatorBridge.java index f57dab3e5313d..0974133ea175c 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/AggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/AggregatorBridge.java @@ -15,6 +15,8 @@ import java.io.IOException; import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.LongFunction; /** * This interface provides a bridge between an aggregator and the optimization context, allowing @@ -75,4 +77,9 @@ void setOptimizationContext(OptimizationContext context) { */ public abstract void tryOptimize(PointValues values, BiConsumer incrementDocCount, final LeafBucketCollector sub) throws IOException; + + /** + * Provides a function to produce bucket ordinals from index of the corresponding range in the range array + */ + protected abstract LongFunction bucketOrdProducer(); } diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java index b73e3f5442117..2d64d32a46303 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java @@ -171,11 +171,6 @@ protected static long getBucketOrd(long bucketOrd) { return bucketOrd; } - /** - * Provides a function to produce bucket ordinals from the lower bound of the range - */ - protected abstract Function bucketOrdProducer(); - /** * Checks whether the top level query matches all documents on the segment * diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java index 016711684f85f..a955ecd88078d 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java @@ -84,7 +84,7 @@ public final void tryOptimize(PointValues values, BiConsumer increme optimizationContext.getRanges(), Integer.MAX_VALUE, (activeIndex, docID) -> { - long ord = bucketOrdProducer().apply(activeIndex); + long ord = bucketOrdProducer().apply((long) activeIndex); try { incrementDocCount.accept(ord, (long) 1); @@ -100,7 +100,7 @@ public final void tryOptimize(PointValues values, BiConsumer increme optimizationContext.getRanges(), Integer.MAX_VALUE, (activeIndex, docCount) -> { - long ord = bucketOrdProducer().apply(activeIndex); + long ord = bucketOrdProducer().apply((long) activeIndex); incrementDocCount.accept(ord, (long) docCount); } ); @@ -108,9 +108,4 @@ public final void tryOptimize(PointValues values, BiConsumer increme optimizationContext.consumeDebugInfo(multiRangesTraverse(treeVisitor)); } - - /** - * Provides a function to produce bucket ordinals from index of the corresponding range in the range array - */ - protected abstract Function bucketOrdProducer(); } diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java index 3924724566e4c..02ed661c99265 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java @@ -72,7 +72,7 @@ public RangeAwareIntersectVisitor(PointValues.PointTree pointTree, PackedValueRa this.activeIndex = packedValueRanges.firstRangeIndex(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); } - public int getActiveIndex() { + public long getActiveIndex() { return activeIndex; }