-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Wire PercentileRanks aggregator into new VS framework #51693
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
polyfractal
merged 9 commits into
elastic:feature/extensible-values-source
from
polyfractal:vs_percentile_ranks_refactor
Mar 3, 2020
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a954b15
Wire Percentiles aggregator into new VS framework
polyfractal ad19003
Wire PercentileRanks aggregator into new VS framework
polyfractal d89f70f
Merge branch 'feature/extensible-values-source' into vs_percentile_ra…
polyfractal d704498
Throw IllegalStateException for bad methods
polyfractal 8a536ed
Merge branch 'feature/extensible-values-source' into vs_percentile_ra…
polyfractal e032424
Merge branch 'feature/extensible-values-source' into vs_percentile_ra…
polyfractal cc6693e
Adjust supported types
polyfractal 1f607c3
Fix formatting
polyfractal dcf014b
Merge branch 'feature/extensible-values-source' into vs_percentile_ra…
polyfractal 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
72 changes: 0 additions & 72 deletions
72
...va/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorFactory.java
This file was deleted.
Oops, something went wrong.
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
123 changes: 123 additions & 0 deletions
123
.../java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.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,123 @@ | ||
| /* | ||
| * 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.index.query.QueryShardContext; | ||
| import org.elasticsearch.search.DocValueFormat; | ||
| import org.elasticsearch.search.aggregations.AggregationExecutionException; | ||
| import org.elasticsearch.search.aggregations.Aggregator; | ||
| import org.elasticsearch.search.aggregations.AggregatorFactories; | ||
| import org.elasticsearch.search.aggregations.AggregatorFactory; | ||
| import org.elasticsearch.search.aggregations.metrics.PercentilesAggregationBuilder.PercentilesConfig; | ||
| 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.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; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory { | ||
| private final double[] values; | ||
| private final PercentilesConfig percentilesConfig; | ||
| private final boolean keyed; | ||
|
|
||
| static void registerAggregators(ValuesSourceRegistry valuesSourceRegistry) { | ||
| valuesSourceRegistry.register(PercentileRanksAggregationBuilder.NAME, | ||
| List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.HISTOGRAM), | ||
polyfractal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new PercentilesAggregatorSupplier() { | ||
| @Override | ||
| public Aggregator build(String name, ValuesSource valuesSource, SearchContext context, Aggregator parent, | ||
| double[] percents, PercentilesConfig percentilesConfig, boolean keyed, DocValueFormat formatter, | ||
| List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { | ||
|
|
||
| if (percentilesConfig.getMethod().equals(PercentilesMethod.TDIGEST)) { | ||
| double compression = ((PercentilesConfig.TDigestConfig)percentilesConfig).getCompression(); | ||
| return new TDigestPercentileRanksAggregator(name, valuesSource, context, parent, percents, compression, keyed, | ||
| formatter, pipelineAggregators, metaData); | ||
| } else if (percentilesConfig.getMethod().equals(PercentilesMethod.HDR)) { | ||
| int numSigFig = ((PercentilesConfig.HdrHistoConfig)percentilesConfig).getNumberOfSignificantValueDigits(); | ||
| return new HDRPercentileRanksAggregator(name, valuesSource, context, parent, percents, numSigFig, keyed, | ||
| formatter, pipelineAggregators, metaData); | ||
| } | ||
|
|
||
| // This should already have thrown but just in case | ||
| throw new IllegalStateException("Unknown percentiles method: [" + percentilesConfig.getMethod().toString() + "]"); | ||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| PercentileRanksAggregatorFactory(String name, ValuesSourceConfig config, double[] values, | ||
| PercentilesConfig percentilesConfig, boolean keyed, | ||
| QueryShardContext queryShardContext, AggregatorFactory parent, | ||
| AggregatorFactories.Builder subFactoriesBuilder, | ||
| Map<String, Object> metaData) throws IOException { | ||
| super(name, config, queryShardContext, parent, subFactoriesBuilder, metaData); | ||
| this.values = values; | ||
| this.percentilesConfig = percentilesConfig; | ||
| this.keyed = keyed; | ||
| } | ||
|
|
||
| @Override | ||
| protected Aggregator createUnmapped(SearchContext searchContext, | ||
| Aggregator parent, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException { | ||
| if (percentilesConfig.getMethod().equals(PercentilesMethod.TDIGEST)) { | ||
| double compression = ((PercentilesConfig.TDigestConfig)percentilesConfig).getCompression(); | ||
| return new TDigestPercentileRanksAggregator(name, null, searchContext, parent, values, compression, keyed, config.format(), | ||
| pipelineAggregators, metaData); | ||
| } else if (percentilesConfig.getMethod().equals(PercentilesMethod.HDR)) { | ||
| int numSigFig = ((PercentilesConfig.HdrHistoConfig)percentilesConfig).getNumberOfSignificantValueDigits(); | ||
| return new HDRPercentileRanksAggregator(name, null, searchContext, parent, values, numSigFig, keyed, | ||
| config.format(), pipelineAggregators, metaData); | ||
| } | ||
|
|
||
| // This should already have thrown but just in case | ||
| throw new IllegalStateException("Unknown percentiles method: [" + percentilesConfig.getMethod().toString() + "]"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Aggregator doCreateInternal(ValuesSource valuesSource, | ||
| SearchContext searchContext, | ||
| Aggregator parent, | ||
| boolean collectsFromSingleBucket, | ||
| List<PipelineAggregator> pipelineAggregators, | ||
| Map<String, Object> metaData) throws IOException { | ||
|
|
||
| AggregatorSupplier aggregatorSupplier = ValuesSourceRegistry.getInstance().getAggregator(config.valueSourceType(), | ||
| PercentileRanksAggregationBuilder.NAME); | ||
|
|
||
| if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) { | ||
| throw new AggregationExecutionException("Registry miss-match - expected PercentilesAggregatorSupplier, found [" + | ||
| aggregatorSupplier.getClass().toString() + "]"); | ||
| } | ||
| PercentilesAggregatorSupplier percentilesAggregatorSupplier = (PercentilesAggregatorSupplier) aggregatorSupplier; | ||
| return percentilesAggregatorSupplier.build(name, valuesSource, searchContext, parent, values, percentilesConfig, keyed, | ||
| config.format(), pipelineAggregators, metaData); | ||
| } | ||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.