mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 09:28:27 +00:00
Fix auto_date_histogram serialization bug (#54447)
This fixes a serialization bug in `auto_date_histogram` that comes up in a cluster mixed between pre-7.3.0 and post-7.3.0. Includes #54429 to keep 7.x looking like master for simpler backports. Closes #54382
This commit is contained in:
parent
ed1edb4964
commit
56047f74be
@ -25,11 +25,9 @@ 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:
|
||||
@ -37,7 +35,7 @@ setup:
|
||||
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 }
|
||||
|
@ -113,20 +113,6 @@ public class AutoDateHistogramAggregationBuilder
|
||||
|
||||
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);
|
||||
@ -141,6 +127,14 @@ public class AutoDateHistogramAggregationBuilder
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
@ -153,19 +147,24 @@ public class AutoDateHistogramAggregationBuilder
|
||||
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 + "]");
|
||||
@ -262,7 +261,17 @@ public class AutoDateHistogramAggregationBuilder
|
||||
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
|
||||
@ -271,7 +280,9 @@ public class AutoDateHistogramAggregationBuilder
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user