Add valuesField in PercentilesAggregationBuilder streamInput constructor (#2308)
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
This commit is contained in:
parent
4395ed560f
commit
e1fd4b75b4
|
@ -163,7 +163,7 @@ public abstract class AbstractPercentilesAggregationBuilder<T extends AbstractPe
|
||||||
this.valuesField = clone.valuesField;
|
this.valuesField = clone.valuesField;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractPercentilesAggregationBuilder(StreamInput in) throws IOException {
|
AbstractPercentilesAggregationBuilder(StreamInput in, ParseField valuesField) throws IOException {
|
||||||
super(in);
|
super(in);
|
||||||
values = in.readDoubleArray();
|
values = in.readDoubleArray();
|
||||||
keyed = in.readBoolean();
|
keyed = in.readBoolean();
|
||||||
|
@ -175,6 +175,7 @@ public abstract class AbstractPercentilesAggregationBuilder<T extends AbstractPe
|
||||||
PercentilesMethod method = PercentilesMethod.readFromStream(in);
|
PercentilesMethod method = PercentilesMethod.readFromStream(in);
|
||||||
percentilesConfig = PercentilesConfig.fromLegacy(method, compression, numberOfSignificantValueDigits);
|
percentilesConfig = PercentilesConfig.fromLegacy(method, compression, numberOfSignificantValueDigits);
|
||||||
}
|
}
|
||||||
|
this.valuesField = valuesField;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class PercentileRanksAggregationBuilder extends AbstractPercentilesAggreg
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentileRanksAggregationBuilder(StreamInput in) throws IOException {
|
public PercentileRanksAggregationBuilder(StreamInput in) throws IOException {
|
||||||
super(in);
|
super(in, VALUES_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PercentileRanksAggregationBuilder(
|
private PercentileRanksAggregationBuilder(
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class PercentilesAggregationBuilder extends AbstractPercentilesAggregatio
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentilesAggregationBuilder(StreamInput in) throws IOException {
|
public PercentilesAggregationBuilder(StreamInput in) throws IOException {
|
||||||
super(in);
|
super(in, PERCENTS_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException {
|
public static AggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException {
|
||||||
|
|
|
@ -118,6 +118,46 @@ public class SearchSourceBuilderTests extends AbstractSearchTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSerializationWithPercentilesQueryObject() throws IOException {
|
||||||
|
String restContent = "{\n"
|
||||||
|
+ " \"aggregations\": {"
|
||||||
|
+ " \"percentiles_duration\": {\n"
|
||||||
|
+ " \"percentiles\" : {\n"
|
||||||
|
+ " \"field\": \"duration\"\n"
|
||||||
|
+ " }\n"
|
||||||
|
+ " }\n"
|
||||||
|
+ " }\n"
|
||||||
|
+ "}\n";
|
||||||
|
String expectedContent = "{\"aggregations\":{"
|
||||||
|
+ "\"percentiles_duration\":{"
|
||||||
|
+ "\"percentiles\":{"
|
||||||
|
+ "\"field\":\"duration\","
|
||||||
|
+ "\"percents\":[1.0,5.0,25.0,50.0,75.0,95.0,99.0],"
|
||||||
|
+ "\"keyed\":true,"
|
||||||
|
+ "\"tdigest\":{"
|
||||||
|
+ "\"compression\":100.0"
|
||||||
|
+ "}"
|
||||||
|
+ "}"
|
||||||
|
+ "}"
|
||||||
|
+ "}}";
|
||||||
|
|
||||||
|
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
|
||||||
|
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(parser);
|
||||||
|
|
||||||
|
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
||||||
|
searchSourceBuilder.writeTo(output);
|
||||||
|
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
|
||||||
|
SearchSourceBuilder deserializedBuilder = new SearchSourceBuilder(in);
|
||||||
|
String actualContent = deserializedBuilder.toString();
|
||||||
|
|
||||||
|
assertEquals(expectedContent, actualContent);
|
||||||
|
assertEquals(searchSourceBuilder.hashCode(), deserializedBuilder.hashCode());
|
||||||
|
assertNotSame(searchSourceBuilder, deserializedBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testShallowCopy() {
|
public void testShallowCopy() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
SearchSourceBuilder original = createSearchSourceBuilder();
|
SearchSourceBuilder original = createSearchSourceBuilder();
|
||||||
|
|
Loading…
Reference in New Issue