From 76bb661023fc4ab37623fe32303fd2d7dc7a4c3b Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 6 Jan 2020 14:32:03 -0500 Subject: [PATCH] Replace AggParseContext with a String (backport of #50625) (#50679) We used to have a *ton* off stuff in the `AggParseContext` but now we parse aggs entirely with named xcontent. So we don't need the context any more. --- .../org/elasticsearch/search/SearchModule.java | 9 ++++----- .../search/aggregations/AggregatorFactories.java | 14 +------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/SearchModule.java b/server/src/main/java/org/elasticsearch/search/SearchModule.java index 492422c6a05..f549881c384 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/server/src/main/java/org/elasticsearch/search/SearchModule.java @@ -101,7 +101,6 @@ import org.elasticsearch.plugins.SearchPlugin.SearchExtensionSpec; import org.elasticsearch.plugins.SearchPlugin.SignificanceHeuristicSpec; import org.elasticsearch.plugins.SearchPlugin.SuggesterSpec; import org.elasticsearch.search.aggregations.AggregationBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.BaseAggregationBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; @@ -462,8 +461,8 @@ public class SearchModule { private void registerAggregation(AggregationSpec spec) { if (false == transportClient) { namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), (p, c) -> { - AggregatorFactories.AggParseContext context = (AggregatorFactories.AggParseContext) c; - return spec.getParser().parse(context.name, p); + String name = (String) c; + return spec.getParser().parse(name, p); })); } namedWriteables.add( @@ -569,8 +568,8 @@ public class SearchModule { private void registerPipelineAggregation(PipelineAggregationSpec spec) { if (false == transportClient) { namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), (p, c) -> { - AggregatorFactories.AggParseContext context = (AggregatorFactories.AggParseContext) c; - return spec.getParser().parse(context.name, p); + String name = (String) c; + return spec.getParser().parse(name, p); })); } namedWriteables.add( diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java b/server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java index 81611f2c8e1..6e3e71a5148 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java @@ -119,8 +119,7 @@ public class AggregatorFactories { + aggregationName + "]: [" + aggBuilder.getType() + "] and [" + fieldName + "]"); } - aggBuilder = parser.namedObject(BaseAggregationBuilder.class, fieldName, - new AggParseContext(aggregationName)); + aggBuilder = parser.namedObject(BaseAggregationBuilder.class, fieldName, aggregationName); } } else { throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.START_OBJECT + "] under [" @@ -151,17 +150,6 @@ public class AggregatorFactories { return factories; } - /** - * Context to parse and aggregation. This should eventually be removed and replaced with a String. - */ - public static final class AggParseContext { - public final String name; - - public AggParseContext(String name) { - this.name = name; - } - } - public static final AggregatorFactories EMPTY = new AggregatorFactories(new AggregatorFactory[0], new ArrayList<>()); private AggregatorFactory[] factories;