We've pretty well settled on `ContextParser` for a generic interface to `ObjectParser`-like-things. This switches the interface used for building parsing pipeline aggregations to `ContextParser` which saves a couple of little wrappers around `ObjectParser`.
This commit is contained in:
parent
f5253d20f7
commit
bfaa487757
|
@ -346,7 +346,8 @@ public interface SearchPlugin {
|
|||
/**
|
||||
* Specification for a {@link PipelineAggregator}.
|
||||
*/
|
||||
class PipelineAggregationSpec extends SearchExtensionSpec<PipelineAggregationBuilder, PipelineAggregator.Parser> {
|
||||
class PipelineAggregationSpec extends SearchExtensionSpec<PipelineAggregationBuilder,
|
||||
ContextParser<String, ? extends PipelineAggregationBuilder>> {
|
||||
private final Map<String, Writeable.Reader<? extends InternalAggregation>> resultReaders = new TreeMap<>();
|
||||
private final Writeable.Reader<? extends PipelineAggregator> aggregatorReader;
|
||||
|
||||
|
@ -364,7 +365,7 @@ public interface SearchPlugin {
|
|||
public PipelineAggregationSpec(ParseField name,
|
||||
Writeable.Reader<? extends PipelineAggregationBuilder> builderReader,
|
||||
Writeable.Reader<? extends PipelineAggregator> aggregatorReader,
|
||||
PipelineAggregator.Parser parser) {
|
||||
ContextParser<String, ? extends PipelineAggregationBuilder> parser) {
|
||||
super(name, builderReader, parser);
|
||||
this.aggregatorReader = aggregatorReader;
|
||||
}
|
||||
|
@ -383,11 +384,52 @@ public interface SearchPlugin {
|
|||
public PipelineAggregationSpec(String name,
|
||||
Writeable.Reader<? extends PipelineAggregationBuilder> builderReader,
|
||||
Writeable.Reader<? extends PipelineAggregator> aggregatorReader,
|
||||
PipelineAggregator.Parser parser) {
|
||||
ContextParser<String, ? extends PipelineAggregationBuilder> parser) {
|
||||
super(name, builderReader, parser);
|
||||
this.aggregatorReader = aggregatorReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specification of a {@link PipelineAggregator}.
|
||||
*
|
||||
* @param name holds the names by which this aggregation might be parsed. The {@link ParseField#getPreferredName()} is special as it
|
||||
* is the name by under which the readers are registered. So it is the name that the {@link PipelineAggregationBuilder} and
|
||||
* {@link PipelineAggregator} should return from {@link NamedWriteable#getWriteableName()}.
|
||||
* @param builderReader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a
|
||||
* {@link StreamInput}
|
||||
* @param aggregatorReader reads the {@link PipelineAggregator} from a stream
|
||||
* @param parser reads the aggregation builder from XContent
|
||||
* @deprecated prefer the ctor that takes a {@link ContextParser}
|
||||
*/
|
||||
@Deprecated
|
||||
public PipelineAggregationSpec(ParseField name,
|
||||
Writeable.Reader<? extends PipelineAggregationBuilder> builderReader,
|
||||
Writeable.Reader<? extends PipelineAggregator> aggregatorReader,
|
||||
PipelineAggregator.Parser parser) {
|
||||
super(name, builderReader, (p, n) -> parser.parse(n, p));
|
||||
this.aggregatorReader = aggregatorReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specification of a {@link PipelineAggregator}.
|
||||
*
|
||||
* @param name name by which this aggregation might be parsed or deserialized. Make sure it is the name that the
|
||||
* {@link PipelineAggregationBuilder} and {@link PipelineAggregator} should return from
|
||||
* {@link NamedWriteable#getWriteableName()}.
|
||||
* @param builderReader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a
|
||||
* {@link StreamInput}
|
||||
* @param aggregatorReader reads the {@link PipelineAggregator} from a stream
|
||||
* @deprecated prefer the ctor that takes a {@link ContextParser}
|
||||
*/
|
||||
@Deprecated
|
||||
public PipelineAggregationSpec(String name,
|
||||
Writeable.Reader<? extends PipelineAggregationBuilder> builderReader,
|
||||
Writeable.Reader<? extends PipelineAggregator> aggregatorReader,
|
||||
PipelineAggregator.Parser parser) {
|
||||
super(name, builderReader, (p, n) -> parser.parse(n, p));
|
||||
this.aggregatorReader = aggregatorReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reader for the shard level results of the aggregation with {@linkplain #getName()}'s {@link ParseField#getPreferredName()}
|
||||
* as the {@link NamedWriteable#getWriteableName()}.
|
||||
|
|
|
@ -531,8 +531,9 @@ public class SearchModule {
|
|||
MovAvgPipelineAggregationBuilder.NAME,
|
||||
MovAvgPipelineAggregationBuilder::new,
|
||||
MovAvgPipelineAggregator::new,
|
||||
(n, c) -> MovAvgPipelineAggregationBuilder.parse(movingAverageModelParserRegistry, n, c))
|
||||
/* Uses InternalHistogram for buckets */);
|
||||
(XContentParser parser, String name) ->
|
||||
MovAvgPipelineAggregationBuilder.parse(movingAverageModelParserRegistry, name, parser)
|
||||
)/* Uses InternalHistogram for buckets */);
|
||||
registerPipelineAggregation(new PipelineAggregationSpec(
|
||||
CumulativeSumPipelineAggregationBuilder.NAME,
|
||||
CumulativeSumPipelineAggregationBuilder::new,
|
||||
|
@ -542,7 +543,7 @@ public class SearchModule {
|
|||
BucketScriptPipelineAggregationBuilder.NAME,
|
||||
BucketScriptPipelineAggregationBuilder::new,
|
||||
BucketScriptPipelineAggregator::new,
|
||||
(name, p) -> BucketScriptPipelineAggregationBuilder.PARSER.parse(p, name)));
|
||||
BucketScriptPipelineAggregationBuilder.PARSER));
|
||||
registerPipelineAggregation(new PipelineAggregationSpec(
|
||||
BucketSelectorPipelineAggregationBuilder.NAME,
|
||||
BucketSelectorPipelineAggregationBuilder::new,
|
||||
|
@ -562,17 +563,15 @@ public class SearchModule {
|
|||
MovFnPipelineAggregationBuilder.NAME,
|
||||
MovFnPipelineAggregationBuilder::new,
|
||||
MovFnPipelineAggregator::new,
|
||||
(name, p) -> MovFnPipelineAggregationBuilder.PARSER.parse(p, name)));
|
||||
MovFnPipelineAggregationBuilder.PARSER));
|
||||
|
||||
registerFromPlugin(plugins, SearchPlugin::getPipelineAggregations, this::registerPipelineAggregation);
|
||||
}
|
||||
|
||||
private void registerPipelineAggregation(PipelineAggregationSpec spec) {
|
||||
if (false == transportClient) {
|
||||
namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), (p, c) -> {
|
||||
String name = (String) c;
|
||||
return spec.getParser().parse(name, p);
|
||||
}));
|
||||
namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(),
|
||||
(p, c) -> spec.getParser().parse(p, (String) c)));
|
||||
}
|
||||
namedWriteables.add(
|
||||
new NamedWriteableRegistry.Entry(PipelineAggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
|
||||
|
|
|
@ -59,7 +59,7 @@ public class AnalyticsPlugin extends Plugin implements SearchPlugin, ActionPlugi
|
|||
CumulativeCardinalityPipelineAggregationBuilder.NAME,
|
||||
CumulativeCardinalityPipelineAggregationBuilder::new,
|
||||
CumulativeCardinalityPipelineAggregator::new,
|
||||
(name, p) -> CumulativeCardinalityPipelineAggregationBuilder.PARSER.parse(p, name))
|
||||
CumulativeCardinalityPipelineAggregationBuilder.PARSER)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue