-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Wire up Max & Min aggregations #52219
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
Changes from 4 commits
570efcd
b5ed20b
79c0439
42d08e4
205a565
5ca64d2
2c278bd
4e69444
a331995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,10 +25,13 @@ | |
| import org.elasticsearch.search.aggregations.AggregatorFactories; | ||
| import org.elasticsearch.search.aggregations.AggregatorFactory; | ||
| import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; | ||
| import org.elasticsearch.search.aggregations.support.AggregatorSupplier; | ||
| import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSource; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; | ||
| import org.elasticsearch.search.internal.SearchContext; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -37,6 +40,23 @@ | |
|
|
||
| class MaxAggregatorFactory extends ValuesSourceAggregatorFactory { | ||
|
|
||
| static void registerAggregators(ValuesSourceRegistry valuesSourceRegistry) { | ||
| valuesSourceRegistry.register(MaxAggregationBuilder.NAME, | ||
| List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I wonder if IP should be on this list? I don't actually know if it works with IP or not, but since NUMERIC == IP in master I suspect it does
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IP is BYTES in master, not NUMERIC. |
||
| new MinMaxAggregatorSupplier() { | ||
| @Override | ||
| public Aggregator build(String name, | ||
| ValuesSourceConfig config, | ||
| ValuesSource valuesSource, | ||
| SearchContext context, | ||
| Aggregator parent, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException { | ||
| return new MaxAggregator(name, config, (Numeric) valuesSource, context, parent, pipelineAggregators, metaData); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| MaxAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext, | ||
| AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder, | ||
| Map<String, Object> metaData) throws IOException { | ||
|
|
@@ -58,10 +78,14 @@ protected Aggregator doCreateInternal(ValuesSource valuesSource, | |
| boolean collectsFromSingleBucket, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException { | ||
| if (valuesSource instanceof Numeric == false) { | ||
| throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for aggregation " + | ||
| this.name()); | ||
| AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), | ||
| MaxAggregationBuilder.NAME); | ||
|
|
||
| if (aggregatorSupplier instanceof MinMaxAggregatorSupplier == false) { | ||
| throw new AggregationExecutionException("Registry miss-match - expected MinMaxAggregatorSupplier, found [" + | ||
| aggregatorSupplier.getClass().toString() + "]"); | ||
| } | ||
| return new MaxAggregator(name, config, (Numeric) valuesSource, searchContext, parent, pipelineAggregators, metaData); | ||
| return ((MinMaxAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, | ||
| pipelineAggregators, metaData); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,10 +25,13 @@ | |
| import org.elasticsearch.search.aggregations.AggregatorFactories; | ||
| import org.elasticsearch.search.aggregations.AggregatorFactory; | ||
| import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; | ||
| import org.elasticsearch.search.aggregations.support.AggregatorSupplier; | ||
| import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSource; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; | ||
| import org.elasticsearch.search.internal.SearchContext; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -37,6 +40,23 @@ | |
|
|
||
| class MinAggregatorFactory extends ValuesSourceAggregatorFactory { | ||
|
|
||
| static void registerAggregators(ValuesSourceRegistry valuesSourceRegistry) { | ||
| valuesSourceRegistry.register(MinAggregationBuilder.NAME, | ||
| List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto question about IP |
||
| new MinMaxAggregatorSupplier() { | ||
| @Override | ||
| public Aggregator build(String name, | ||
| ValuesSourceConfig config, | ||
| ValuesSource valuesSource, | ||
| SearchContext context, | ||
| Aggregator parent, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException { | ||
| return new MinAggregator(name, config, (Numeric) valuesSource, context, parent, pipelineAggregators, metaData); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| MinAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext, | ||
| AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder, | ||
| Map<String, Object> metaData) throws IOException { | ||
|
|
@@ -58,10 +78,14 @@ protected Aggregator doCreateInternal(ValuesSource valuesSource, | |
| boolean collectsFromSingleBucket, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException { | ||
| if (valuesSource instanceof Numeric == false) { | ||
| throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for aggregation " + | ||
| this.name()); | ||
| AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), | ||
| MinAggregationBuilder.NAME); | ||
|
|
||
| if (aggregatorSupplier instanceof MinMaxAggregatorSupplier == false) { | ||
| throw new AggregationExecutionException("Registry miss-match - expected MinMaxAggregatorSupplier, found [" + | ||
| aggregatorSupplier.getClass().toString() + "]"); | ||
| } | ||
| return new MinAggregator(name, config, (Numeric) valuesSource, searchContext, parent, pipelineAggregators, metaData); | ||
| return ((MinMaxAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, | ||
| pipelineAggregators, metaData); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.metrics; | ||
|
|
||
| import org.elasticsearch.search.aggregations.Aggregator; | ||
| import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; | ||
| import org.elasticsearch.search.aggregations.support.AggregatorSupplier; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSource; | ||
| import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; | ||
| import org.elasticsearch.search.internal.SearchContext; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public interface MinMaxAggregatorSupplier extends AggregatorSupplier { | ||
| Aggregator build(String name, | ||
| ValuesSourceConfig config, | ||
| ValuesSource valuesSource, | ||
| SearchContext context, | ||
| Aggregator parent, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put these on the next line? We should probably come up with an overall formatting for these anyhow, I think they are all over the place depending on the agg and the PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we supposed to have an autoformater for this now? ;)
I think I like putting it on a new line slightly better, not sure why I didn't do that here. I'll push an update.