Skip to content

Commit

Permalink
Add valuesField in PercentilesAggregationBuilder streamInput construc…
Browse files Browse the repository at this point in the history
…tor (#2308)

Signed-off-by: Subhobrata Dey <[email protected]>
  • Loading branch information
sbcd90 authored Mar 7, 2022
1 parent 4395ed5 commit e1fd4b7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static <T extends AbstractPercentilesAggregationBuilder<T>> ConstructingO
this.valuesField = clone.valuesField;
}

AbstractPercentilesAggregationBuilder(StreamInput in) throws IOException {
AbstractPercentilesAggregationBuilder(StreamInput in, ParseField valuesField) throws IOException {
super(in);
values = in.readDoubleArray();
keyed = in.readBoolean();
Expand All @@ -175,6 +175,7 @@ public static <T extends AbstractPercentilesAggregationBuilder<T>> ConstructingO
PercentilesMethod method = PercentilesMethod.readFromStream(in);
percentilesConfig = PercentilesConfig.fromLegacy(method, compression, numberOfSignificantValueDigits);
}
this.valuesField = valuesField;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private PercentileRanksAggregationBuilder(String name, double[] values, Percenti
}

public PercentileRanksAggregationBuilder(StreamInput in) throws IOException {
super(in);
super(in, VALUES_FIELD);
}

private PercentileRanksAggregationBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
}

public PercentilesAggregationBuilder(StreamInput in) throws IOException {
super(in);
super(in, PERCENTS_FIELD);
}

public static AggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,46 @@ public void testSerialization() throws IOException {
}
}

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() {
for (int i = 0; i < 10; i++) {
SearchSourceBuilder original = createSearchSourceBuilder();
Expand Down

0 comments on commit e1fd4b7

Please sign in to comment.