Skip to content

Commit

Permalink
Rollup ignores time_zone on date histogram (#40844)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimczi committed Apr 4, 2019
1 parent 629d2ea commit fa82df0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ private static List<AggregationBuilder> translateDateHistogram(DateHistogramAggr
filterConditions.add(new TermQueryBuilder(RollupField.formatFieldName(source,
DateHistogramGroupConfig.TIME_ZONE), timezone));

if (source.timeZone() != null) {
rolledDateHisto.timeZone(source.timeZone());
}
rolledDateHisto.offset(source.offset());
if (source.extendedBounds() != null) {
rolledDateHisto.extendedBounds(source.extendedBounds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.Before;

import java.io.IOException;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -271,6 +272,37 @@ public void testDateHistoLongIntervalWithMinMax() {
}
}

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() {
List<QueryBuilder> filterConditions = new ArrayList<>();
List<AggregationBuilder> translated = translateAggregation(new AvgAggregationBuilder("test_metric")
Expand Down

0 comments on commit fa82df0

Please sign in to comment.