Date Histogram Facet: Add `pre_zone_adjust_large_interval`, closes #1744.
This commit is contained in:
parent
0d3dd3845d
commit
078f220b6f
|
@ -51,6 +51,8 @@ public abstract class TimeZoneRounding {
|
|||
private long preOffset;
|
||||
private long postOffset;
|
||||
|
||||
private boolean preZoneAdjustLargeInterval = false;
|
||||
|
||||
public Builder(DateTimeField field) {
|
||||
this.field = field;
|
||||
this.interval = -1;
|
||||
|
@ -66,6 +68,11 @@ public abstract class TimeZoneRounding {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder preZoneAdjustLargeInterval(boolean preZoneAdjustLargeInterval) {
|
||||
this.preZoneAdjustLargeInterval = preZoneAdjustLargeInterval;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder postZone(DateTimeZone postTz) {
|
||||
this.postTz = postTz;
|
||||
return this;
|
||||
|
@ -91,7 +98,7 @@ public abstract class TimeZoneRounding {
|
|||
if (field != null) {
|
||||
if (preTz.equals(DateTimeZone.UTC) && postTz.equals(DateTimeZone.UTC)) {
|
||||
timeZoneRounding = new UTCTimeZoneRoundingFloor(field);
|
||||
} else if (field.getDurationField().getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12) {
|
||||
} else if (preZoneAdjustLargeInterval || field.getDurationField().getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12) {
|
||||
timeZoneRounding = new TimeTimeZoneRoundingFloor(field, preTz, postTz);
|
||||
} else {
|
||||
timeZoneRounding = new DayTimeZoneRoundingFloor(field, preTz, postTz);
|
||||
|
@ -99,7 +106,7 @@ public abstract class TimeZoneRounding {
|
|||
} else {
|
||||
if (preTz.equals(DateTimeZone.UTC) && postTz.equals(DateTimeZone.UTC)) {
|
||||
timeZoneRounding = new UTCIntervalTimeZoneRounding(interval);
|
||||
} else if (interval < DateTimeConstants.MILLIS_PER_HOUR * 12) {
|
||||
} else if (preZoneAdjustLargeInterval || interval < DateTimeConstants.MILLIS_PER_HOUR * 12) {
|
||||
timeZoneRounding = new TimeIntervalTimeZoneRounding(interval, preTz, postTz);
|
||||
} else {
|
||||
timeZoneRounding = new DayIntervalTimeZoneRounding(interval, preTz, postTz);
|
||||
|
@ -131,7 +138,7 @@ public abstract class TimeZoneRounding {
|
|||
public long calc(long utcMillis) {
|
||||
long time = utcMillis + preTz.getOffset(utcMillis);
|
||||
time = field.roundFloor(time);
|
||||
// now, time is still in local, move it to UTC
|
||||
// now, time is still in local, move it to UTC (or the adjustLargeInterval flag is set)
|
||||
time = time - preTz.getOffset(time);
|
||||
// now apply post Tz
|
||||
time = time + postTz.getOffset(time);
|
||||
|
|
|
@ -38,6 +38,7 @@ public class DateHistogramFacetBuilder extends AbstractFacetBuilder {
|
|||
private String interval = null;
|
||||
private String preZone = null;
|
||||
private String postZone = null;
|
||||
private Boolean preZoneAdjustLargeInterval;
|
||||
long preOffset = 0;
|
||||
long postOffset = 0;
|
||||
float factor = 1.0f;
|
||||
|
@ -114,6 +115,14 @@ public class DateHistogramFacetBuilder extends AbstractFacetBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should pre zone be adjusted for large (day and above) intervals. Defaults to <tt>false</tt>.
|
||||
*/
|
||||
public DateHistogramFacetBuilder preZoneAdjustLargeInterval(boolean preZoneAdjustLargeInterval) {
|
||||
this.preZoneAdjustLargeInterval = preZoneAdjustLargeInterval;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pre time zone to use when bucketing the values. This timezone will be applied before
|
||||
* rounding off the result.
|
||||
|
@ -236,6 +245,9 @@ public class DateHistogramFacetBuilder extends AbstractFacetBuilder {
|
|||
if (preZone != null) {
|
||||
builder.field("pre_zone", preZone);
|
||||
}
|
||||
if (preZoneAdjustLargeInterval != null) {
|
||||
builder.field("pre_zone_adjust_large_interval", preZoneAdjustLargeInterval);
|
||||
}
|
||||
if (postZone != null) {
|
||||
builder.field("post_zone", postZone);
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
|
|||
String interval = null;
|
||||
DateTimeZone preZone = DateTimeZone.UTC;
|
||||
DateTimeZone postZone = DateTimeZone.UTC;
|
||||
boolean preZoneAdjustLargeInterval = false;
|
||||
long preOffset = 0;
|
||||
long postOffset = 0;
|
||||
float factor = 1.0f;
|
||||
|
@ -115,6 +116,8 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
|
|||
preZone = parseZone(parser, token);
|
||||
} else if ("pre_zone".equals(fieldName) || "preZone".equals(fieldName)) {
|
||||
preZone = parseZone(parser, token);
|
||||
} else if ("pre_zone_adjust_large_interval".equals(fieldName) || "preZoneAdjustLargeInterval".equals(fieldName)) {
|
||||
preZoneAdjustLargeInterval = parser.booleanValue();
|
||||
} else if ("post_zone".equals(fieldName) || "postZone".equals(fieldName)) {
|
||||
postZone = parseZone(parser, token);
|
||||
} else if ("pre_offset".equals(fieldName) || "preOffset".equals(fieldName)) {
|
||||
|
@ -160,6 +163,7 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
|
|||
|
||||
TimeZoneRounding tzRounding = tzRoundingBuilder
|
||||
.preZone(preZone).postZone(postZone)
|
||||
.preZoneAdjustLargeInterval(preZoneAdjustLargeInterval)
|
||||
.preOffset(preOffset).postOffset(postOffset)
|
||||
.factor(factor)
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue