-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Move top-level pipeline aggs out of QuerySearchResult #40319
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
javanna
merged 9 commits into
elastic:master
from
javanna:enhancement/query_search_result_remove_pipeline_aggs
Mar 28, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18365a9
Move top-level pipeline aggs out of QuerySearchResult
javanna fa6bb04
Merge branch 'master' into enhancement/query_search_result_remove_pip…
javanna 64fb309
address review comments
javanna 56cd793
add tests
javanna 11fe5da
add tests
javanna 5852f0d
Merge branch 'master' into enhancement/query_search_result_remove_pip…
javanna 4d4fa33
update versions and disable bwc tests
javanna bef9315
remove redundant test, will be added to 7.x only
javanna b4ec1bd
Merge branch 'master' into enhancement/query_search_result_remove_pip…
javanna 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
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
102 changes: 102 additions & 0 deletions
102
server/src/test/java/org/elasticsearch/search/query/QuerySearchResultTests.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,102 @@ | ||
| /* | ||
| * 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.query; | ||
|
|
||
| import org.apache.lucene.search.ScoreDoc; | ||
| import org.apache.lucene.search.TopDocs; | ||
| import org.apache.lucene.search.TotalHits; | ||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.action.OriginalIndices; | ||
| import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
| import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.search.DocValueFormat; | ||
| import org.elasticsearch.search.SearchModule; | ||
| import org.elasticsearch.search.SearchShardTarget; | ||
| import org.elasticsearch.search.aggregations.Aggregations; | ||
| import org.elasticsearch.search.aggregations.InternalAggregations; | ||
| import org.elasticsearch.search.aggregations.InternalAggregationsTests; | ||
| import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator; | ||
| import org.elasticsearch.search.suggest.SuggestTests; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.test.VersionUtils; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
|
|
||
| public class QuerySearchResultTests extends ESTestCase { | ||
|
|
||
| private final NamedWriteableRegistry namedWriteableRegistry; | ||
|
|
||
| public QuerySearchResultTests() { | ||
| SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList()); | ||
| this.namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables()); | ||
| } | ||
|
|
||
| private static QuerySearchResult createTestInstance() throws Exception { | ||
| ShardId shardId = new ShardId("index", "uuid", randomInt()); | ||
| QuerySearchResult result = new QuerySearchResult(randomLong(), new SearchShardTarget("node", shardId, null, OriginalIndices.NONE)); | ||
| if (randomBoolean()) { | ||
| result.terminatedEarly(randomBoolean()); | ||
| } | ||
| TopDocs topDocs = new TopDocs(new TotalHits(randomLongBetween(0, Long.MAX_VALUE), TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]); | ||
| result.topDocs(new TopDocsAndMaxScore(topDocs, randomBoolean() ? Float.NaN : randomFloat()), new DocValueFormat[0]); | ||
| result.size(randomInt()); | ||
| result.from(randomInt()); | ||
| if (randomBoolean()) { | ||
| result.suggest(SuggestTests.createTestItem()); | ||
| } | ||
| if (randomBoolean()) { | ||
| result.aggregations(InternalAggregationsTests.createTestInstance()); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public void testSerialization() throws Exception { | ||
| QuerySearchResult querySearchResult = createTestInstance(); | ||
| Version version = VersionUtils.randomVersion(random()); | ||
| QuerySearchResult deserialized = copyStreamable(querySearchResult, namedWriteableRegistry, QuerySearchResult::new, version); | ||
| assertEquals(querySearchResult.getRequestId(), deserialized.getRequestId()); | ||
| assertNull(deserialized.getSearchShardTarget()); | ||
| assertEquals(querySearchResult.topDocs().maxScore, deserialized.topDocs().maxScore, 0f); | ||
| assertEquals(querySearchResult.topDocs().topDocs.totalHits, deserialized.topDocs().topDocs.totalHits); | ||
| assertEquals(querySearchResult.from(), deserialized.from()); | ||
| assertEquals(querySearchResult.size(), deserialized.size()); | ||
| assertEquals(querySearchResult.hasAggs(), deserialized.hasAggs()); | ||
| if (deserialized.hasAggs()) { | ||
| Aggregations aggs = querySearchResult.consumeAggs(); | ||
| Aggregations deserializedAggs = deserialized.consumeAggs(); | ||
| assertEquals(aggs.asList(), deserializedAggs.asList()); | ||
| List<SiblingPipelineAggregator> pipelineAggs = ((InternalAggregations) aggs).getTopLevelPipelineAggregators(); | ||
| List<SiblingPipelineAggregator> deserializedPipelineAggs = | ||
| ((InternalAggregations) deserializedAggs).getTopLevelPipelineAggregators(); | ||
| assertEquals(pipelineAggs.size(), deserializedPipelineAggs.size()); | ||
| for (int i = 0; i < pipelineAggs.size(); i++) { | ||
| SiblingPipelineAggregator pipelineAgg = pipelineAggs.get(i); | ||
| SiblingPipelineAggregator deserializedPipelineAgg = deserializedPipelineAggs.get(i); | ||
| assertArrayEquals(pipelineAgg.bucketsPaths(), deserializedPipelineAgg.bucketsPaths()); | ||
| assertEquals(pipelineAgg.name(), deserializedPipelineAgg.name()); | ||
| } | ||
| } | ||
| assertEquals(querySearchResult.terminatedEarly(), deserialized.terminatedEarly()); | ||
| } | ||
| } |
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.
Can we skip the rewriting if siblings are empty ?