Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add valuesField in PercentilesAggregationBuilder streamInput constructor #2308

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 @@ -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