Rollup ignores time_zone on date histogram (#40844)
When translating the original aggregation for the rollup indices, the timezone of the date histogram is validated against the rollup job but the value is not copied in the newly created date_histogram.
This commit is contained in:
parent
075078e7e0
commit
a15f55b2de
|
@ -224,6 +224,9 @@ public class RollupRequestTranslator {
|
||||||
filterConditions.add(new TermQueryBuilder(RollupField.formatFieldName(source,
|
filterConditions.add(new TermQueryBuilder(RollupField.formatFieldName(source,
|
||||||
DateHistogramGroupConfig.TIME_ZONE), timezone));
|
DateHistogramGroupConfig.TIME_ZONE), timezone));
|
||||||
|
|
||||||
|
if (source.timeZone() != null) {
|
||||||
|
rolledDateHisto.timeZone(source.timeZone());
|
||||||
|
}
|
||||||
rolledDateHisto.offset(source.offset());
|
rolledDateHisto.offset(source.offset());
|
||||||
if (source.extendedBounds() != null) {
|
if (source.extendedBounds() != null) {
|
||||||
rolledDateHisto.extendedBounds(source.extendedBounds());
|
rolledDateHisto.extendedBounds(source.extendedBounds());
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hamcrest.Matchers;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -271,6 +272,37 @@ public class RollupRequestTranslationTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDateHistoWithTimezone() {
|
||||||
|
ZoneId timeZone = ZoneId.of(randomFrom(ZoneId.getAvailableZoneIds()));
|
||||||
|
DateHistogramAggregationBuilder histo = new DateHistogramAggregationBuilder("test_histo");
|
||||||
|
histo.interval(86400000)
|
||||||
|
.field("foo")
|
||||||
|
.timeZone(timeZone);
|
||||||
|
List<QueryBuilder> filterConditions = new ArrayList<>();
|
||||||
|
|
||||||
|
List<AggregationBuilder> translated = translateAggregation(histo, filterConditions, namedWriteableRegistry);
|
||||||
|
assertThat(translated.size(), equalTo(1));
|
||||||
|
assertThat(translated.get(0), instanceOf(DateHistogramAggregationBuilder.class));
|
||||||
|
DateHistogramAggregationBuilder translatedHisto = (DateHistogramAggregationBuilder)translated.get(0);
|
||||||
|
|
||||||
|
assertThat(translatedHisto.interval(), equalTo(86400000L));
|
||||||
|
assertThat(translatedHisto.field(), equalTo("foo.date_histogram.timestamp"));
|
||||||
|
assertThat(translatedHisto.timeZone(), equalTo(timeZone));
|
||||||
|
assertThat(filterConditions.size(), equalTo(1));
|
||||||
|
|
||||||
|
for (QueryBuilder q : filterConditions) {
|
||||||
|
if (q instanceof TermQueryBuilder) {
|
||||||
|
if (((TermQueryBuilder) q).fieldName().equals("foo.date_histogram.time_zone")) {
|
||||||
|
assertThat(((TermQueryBuilder) q).value(), equalTo(timeZone.toString()));
|
||||||
|
} else {
|
||||||
|
fail("Unexpected Term Query in filter conditions: [" + ((TermQueryBuilder) q).fieldName() + "]");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fail("Unexpected query builder in filter conditions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testAvgMetric() {
|
public void testAvgMetric() {
|
||||||
List<QueryBuilder> filterConditions = new ArrayList<>();
|
List<QueryBuilder> filterConditions = new ArrayList<>();
|
||||||
List<AggregationBuilder> translated = translateAggregation(new AvgAggregationBuilder("test_metric")
|
List<AggregationBuilder> translated = translateAggregation(new AvgAggregationBuilder("test_metric")
|
||||||
|
|
Loading…
Reference in New Issue