Skip to content
Merged
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 @@ -288,11 +288,15 @@ public Rounding createRounding(ZoneId timeZone) {
} else {
// We're not sure what the interval was originally (legacy) so use old behavior of assuming
// calendar first, then fixed. Required because fixed/cal overlap in places ("1h")
DateTimeUnit intervalAsUnit = tryIntervalAsCalendarUnit();
if (intervalAsUnit != null) {
tzRoundingBuilder = Rounding.builder(tryIntervalAsCalendarUnit());
DateTimeUnit calInterval = tryIntervalAsCalendarUnit();
TimeValue fixedInterval = tryIntervalAsFixedUnit();
if (calInterval != null) {
tzRoundingBuilder = Rounding.builder(calInterval);
} else if (fixedInterval != null) {
tzRoundingBuilder = Rounding.builder(fixedInterval);
} else {
tzRoundingBuilder = Rounding.builder(tryIntervalAsFixedUnit());
// If we get here we have exhausted our options and are not able to parse this interval
throw new IllegalArgumentException("Unable to parse interval [" + dateHistogramInterval + "]");
}
}
if (timeZone != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,16 @@ public void testLegacyThenNew() throws IOException {
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
}

public void testIllegalInterval() throws IOException {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
Collections.emptyList(),
aggregation -> aggregation.dateHistogramInterval(new DateHistogramInterval("foobar")).field(DATE_FIELD),
histogram -> {}
));
assertThat(e.getMessage(), equalTo("Unable to parse interval [foobar]"));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
}

private void testSearchCase(Query query, List<String> dataset,
Consumer<DateHistogramAggregationBuilder> configure,
Consumer<InternalDateHistogram> verify) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,7 @@ setup:

---
"Search error against live index":
- skip:
version: "all"
reason: "AwaitsFix: https://github.com/elastic/elasticsearch/issues/41970"

- do:
catch: bad_request
rollup.rollup_search:
Expand All @@ -1264,9 +1262,7 @@ setup:

---
"Search error against rollup and live index":
- skip:
version: "all"
reason: "AwaitsFix: https://github.com/elastic/elasticsearch/issues/41970"

- do:
catch: bad_request
rollup.rollup_search:
Expand Down