Skip to content

Commit

Permalink
auto date histo get rounding method should be idempotent
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Feb 2, 2024
1 parent 8573fe5 commit 710688a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static long[] getBoundsWithRangeQuery(PointRangeQuery prq, String fieldN
if (lower > upper) {
return null;
}
return new long[]{lower, upper};
return new long[] { lower, upper };
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ protected Rounding getRounding(final long low, final long high) {
// since we cannot exceed targetBuckets, bestDuration should go up,
// so the right innerInterval should be an upper bound
long bestDuration = (high - low) / targetBuckets;
// reset so this function is idempotent
roundingIdx = 0;
while (roundingIdx < roundingInfos.length - 1) {
final RoundingInfo curRoundingInfo = roundingInfos[roundingIdx];
final int temp = curRoundingInfo.innerIntervals[curRoundingInfo.innerIntervals.length - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,7 @@ public void testRangeQuery() throws IOException {
testSearchCase(
LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2018-01-01"), asLong("2020-01-01")),
Arrays.asList("2017-02-01", "2017-02-02", "2017-02-02", "2017-02-03", "2017-02-03", "2017-02-03", "2017-02-05"),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY)
.field(AGGREGABLE_DATE),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY).field(AGGREGABLE_DATE),
histogram -> {
List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
assertEquals(0, buckets.size());
Expand All @@ -1270,8 +1269,7 @@ public void testRangeQuery() throws IOException {
testSearchCase(
LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2016-01-01"), asLong("2017-01-01")),
Arrays.asList("2017-02-01", "2017-02-02", "2017-02-02", "2017-02-03", "2017-02-03", "2017-02-03", "2017-02-05"),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY)
.field(AGGREGABLE_DATE),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY).field(AGGREGABLE_DATE),
histogram -> {
List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
assertEquals(0, buckets.size());
Expand All @@ -1282,8 +1280,7 @@ public void testRangeQuery() throws IOException {
testSearchCase(
LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2016-01-01"), asLong("2017-02-02")),
Arrays.asList("2017-02-01", "2017-02-02", "2017-02-02", "2017-02-03", "2017-02-03", "2017-02-03", "2017-02-05"),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY)
.field(AGGREGABLE_DATE),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY).field(AGGREGABLE_DATE),
histogram -> {
List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
assertEquals(2, buckets.size());
Expand All @@ -1302,8 +1299,7 @@ public void testRangeQuery() throws IOException {
testSearchCase(
LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2017-02-03"), asLong("2020-01-01")),
Arrays.asList("2017-02-01", "2017-02-02", "2017-02-02", "2017-02-03", "2017-02-03", "2017-02-03", "2017-02-05"),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY)
.field(AGGREGABLE_DATE),
aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY).field(AGGREGABLE_DATE),
histogram -> {
List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
assertEquals(3, buckets.size());
Expand Down

0 comments on commit 710688a

Please sign in to comment.