From b5359341410510ebb7ebc23fa92b14dda47178e1 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 28 Nov 2023 00:01:44 +0530 Subject: [PATCH] Finally fixing hardbounds test case Signed-off-by: Ankit Jain --- .../histogram/DateHistogramAggregator.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 659cb54d3affe..bf3af306d7005 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 @@ -133,7 +133,7 @@ class DateHistogramAggregator extends BucketsAggregator implements SizedBucketAg // Update min/max limit if user specified any hard bounds if (hardBounds != null) { bounds[0] = Math.max(bounds[0], hardBounds.getMin()); - bounds[1] = Math.min(bounds[1], hardBounds.getMax()); + bounds[1] = Math.min(bounds[1], hardBounds.getMax() - 1); // hard bounds max is exclusive } filters = FilterRewriteHelper.createFilterForAggregations( @@ -286,18 +286,20 @@ private boolean tryFastFilterAggregation(LeafReaderContext ctx, long owningBucke } for (i = 0; i < filters.length; i++) { - long bucketOrd = bucketOrds.add( - owningBucketOrd, - preparedRounding.round( - fieldType.convertNanosToMillis( - NumericUtils.sortableBytesToLong(((PointRangeQuery) filters[i].getQuery()).getLowerPoint(), 0) + if (counts[i] > 0) { + long bucketOrd = bucketOrds.add( + owningBucketOrd, + preparedRounding.round( + fieldType.convertNanosToMillis( + NumericUtils.sortableBytesToLong(((PointRangeQuery) filters[i].getQuery()).getLowerPoint(), 0) + ) ) - ) - ); - if (bucketOrd < 0) { // already seen - bucketOrd = -1 - bucketOrd; + ); + if (bucketOrd < 0) { // already seen + bucketOrd = -1 - bucketOrd; + } + incrementBucketDocCount(bucketOrd, counts[i]); } - incrementBucketDocCount(bucketOrd, counts[i]); } throw new CollectionTerminatedException(); }