-
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
Merged
not-napoleon
merged 9 commits into
elastic:feature/extensible-values-source
from
not-napoleon:vs-refactor-wire-up-max
Feb 24, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
570efcd
Wire up max aggregator
not-napoleon b5ed20b
Wire up min aggregation
not-napoleon 79c0439
Rename for clarity
not-napoleon 42d08e4
Merge branch 'feature/extensible-values-source' into vs-refactor-wire…
not-napoleon 205a565
added a test for min aggregation over IPs
not-napoleon 5ca64d2
Merge branch 'feature/extensible-values-source' into vs-refactor-wire…
not-napoleon 2c278bd
clean up indentation
not-napoleon 4e69444
Merge branch 'feature/extensible-values-source' into vs-refactor-wire…
not-napoleon a331995
remove unused imports
not-napoleon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/elasticsearch/search/aggregations/metrics/MinMaxAggregatorSupplier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
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.
IP is BYTES in master, not NUMERIC.