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 @@ -25,19 +25,17 @@ setup:

---
"basic":
- skip:
version: " - 7.7.99"
reason: Tracked in https://github.com/elastic/elasticsearch/issues/54382
- do:
search:
rest_total_hits_as_int: true
body:
size: 0
aggs:
histo:
auto_date_histogram:
field: date
buckets: 2
- match: { hits.total.value: 4 }
- match: { hits.total: 4 }
- length: { aggregations.histo.buckets: 2 }
- match: { aggregations.histo.buckets.0.key_as_string: "2020-03-01T00:00:00.000Z" }
- match: { aggregations.histo.buckets.0.doc_count: 2 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ static RoundingInfo[] buildRoundings(ZoneId timeZone, String minimumInterval) {

private String minimumIntervalExpression;

public String getMinimumIntervalExpression() {
return minimumIntervalExpression;
}

public AutoDateHistogramAggregationBuilder setMinimumIntervalExpression(String minimumIntervalExpression) {
if (minimumIntervalExpression != null && !ALLOWED_INTERVALS.containsValue(minimumIntervalExpression)) {
throw new IllegalArgumentException(MINIMUM_INTERVAL_FIELD.getPreferredName() +
" must be one of [" + ALLOWED_INTERVALS.values().toString() + "]");
}
this.minimumIntervalExpression = minimumIntervalExpression;
return this;
}


/** Create a new builder with the given name. */
public AutoDateHistogramAggregationBuilder(String name) {
super(name, CoreValuesSourceType.NUMERIC, ValueType.DATE);
Expand All @@ -141,6 +127,14 @@ public AutoDateHistogramAggregationBuilder(StreamInput in) throws IOException {
}
}

@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeVInt(numBuckets);
if (out.getVersion().onOrAfter(Version.V_7_3_0)) {
out.writeOptionalString(minimumIntervalExpression);
}
}

protected AutoDateHistogramAggregationBuilder(AutoDateHistogramAggregationBuilder clone, Builder factoriesBuilder,
Map<String, Object> metaData) {
super(clone, factoriesBuilder, metaData);
Expand All @@ -153,19 +147,24 @@ protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, O
return new AutoDateHistogramAggregationBuilder(this, factoriesBuilder, metaData);
}

@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeVInt(numBuckets);
if (out.getVersion().onOrAfter(Version.V_7_3_0)) {
out.writeOptionalString(minimumIntervalExpression);
}
}

@Override
public String getType() {
return NAME;
}

public String getMinimumIntervalExpression() {
return minimumIntervalExpression;
}

public AutoDateHistogramAggregationBuilder setMinimumIntervalExpression(String minimumIntervalExpression) {
if (minimumIntervalExpression != null && !ALLOWED_INTERVALS.containsValue(minimumIntervalExpression)) {
throw new IllegalArgumentException(MINIMUM_INTERVAL_FIELD.getPreferredName() +
" must be one of [" + ALLOWED_INTERVALS.values().toString() + "]");
}
this.minimumIntervalExpression = minimumIntervalExpression;
return this;
}

public AutoDateHistogramAggregationBuilder setNumBuckets(int numBuckets) {
if (numBuckets <= 0) {
throw new IllegalArgumentException(NUM_BUCKETS_FIELD.getPreferredName() + " must be greater than 0 for [" + name + "]");
Expand Down Expand Up @@ -262,7 +261,17 @@ public RoundingInfo(StreamInput in) throws IOException {
roughEstimateDurationMillis = in.readVLong();
innerIntervals = in.readIntArray();
unitAbbreviation = in.readString();
dateTimeUnit = in.readString();
if (in.getVersion().onOrAfter(Version.V_7_3_0)) {
dateTimeUnit = in.readString();
} else {
/*
* This *should* be safe because we only deserialize RoundingInfo
* when reading result and results don't actually use this at all.
* We just set it to something non-null to line up with the normal
* ctor. "seconds" is the smallest unit anyway.
*/
dateTimeUnit = "second";
}
}

@Override
Expand All @@ -271,7 +280,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(roughEstimateDurationMillis);
out.writeIntArray(innerIntervals);
out.writeString(unitAbbreviation);
out.writeString(dateTimeUnit);
if (out.getVersion().onOrAfter(Version.V_7_3_0)) {
out.writeString(dateTimeUnit);
}
}

public int getMaximumInnerInterval() {
Expand Down