Skip to content
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

Adds metadata to rewritten aggregations #28185

Merged
merged 2 commits into from
Jan 15, 2018
Merged

Adds metadata to rewritten aggregations #28185

merged 2 commits into from
Jan 15, 2018

Conversation

colings86
Copy link
Contributor

Previous to this change, if any filters in the filters aggregation were rewritten, the rewritten version of the FiltersAggregationBuilder would not contain the metadata form the original. This is because AbstractAggregationBuilder.getMetadata() returns an empty map when not metadata is set.

Closes #28170

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment regarding where the metadata should be copied.

@@ -101,7 +101,7 @@ public final AggregationBuilder rewrite(QueryRewriteContext context) throws IOEx
if (rewritten == this) {
return rewritten;
}
if (getMetaData() != null && rewritten.getMetaData() == null) {
if (getMetaData() != null && (rewritten.getMetaData() == null || rewritten.getMetaData().isEmpty())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the agg be responsible for copying the metadata when it's rewritten ? This is a bit confusing now since we don't know if the rewritten metadata is empty on purpose or not. We could just copy the metadata explicitly in Filter(s)Agg...#doRewrite to avoid ambiguity ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I have been thinking about it is that this superclass manages the metadata in every other respect (toXContent, setters, getters) so it seem natural to me that it would handle the metadata while rewriting the agg? This way the way that metadata is handled should be consistent across all aggregations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is a bit confusing because AbractAggregationBuilder handles some of the metadata stuff too, but since most if not all aggregations extend AbstractAggregationBuilder I think it is still nice to have consistent logic for metadata across all the aggs. Maybe separately we should look at whether we still need AggregationBuilder and AbstractAggregationBuilder or if we could merge them to make things a bit simpler?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe separately we should look at whether we still need AggregationBuilder and AbstractAggregationBuilder or if we could merge them to make things a bit simpler?

agreed, it will also simplify the fix for #27782 which requires a new clone function.

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can revisit if we merge AbractAggregationBuilder and AggregationBuilder

Previous to this change, if any filters in the filters aggregation were rewritten, the rewritten version of the FiltersAggregationBuilder would not contain the metadata form the original. This is because `AbstractAggregationBuilder.getMetadata()` returns an empty map when not metadata is set.

Closes #28170
@colings86
Copy link
Contributor Author

jenkins test this please

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good, but I'm wondering why we can't always blindly copy the metadata to the rewritten aggregation?

@@ -101,7 +101,7 @@ public final AggregationBuilder rewrite(QueryRewriteContext context) throws IOEx
if (rewritten == this) {
return rewritten;
}
if (getMetaData() != null && rewritten.getMetaData() == null) {
if (getMetaData() != null && (rewritten.getMetaData() == null || rewritten.getMetaData().isEmpty())) {
rewritten.setMetaData(getMetaData());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what prevents us from always blindly setting the metadata? Rewriting should never modify it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. I'll change it to do this since it simplifies things

@colings86 colings86 merged commit 023d08e into elastic:master Jan 15, 2018
@colings86 colings86 deleted the fix/28170 branch January 15, 2018 09:14
colings86 added a commit that referenced this pull request Jan 15, 2018
* Adds metadata to rewritten aggregations

Previous to this change, if any filters in the filters aggregation were rewritten, the rewritten version of the FiltersAggregationBuilder would not contain the metadata form the original. This is because `AbstractAggregationBuilder.getMetadata()` returns an empty map when not metadata is set.

Closes #28170

* Always set metadata when rewritten
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Jan 15, 2018
* master: (21 commits)
  [GEO] Add WKT Support to GeoBoundingBoxQueryBuilder
  Painless: Add whitelist extensions (elastic#28161)
  Fix daitch_mokotoff phonetic filter to use the dedicated Lucene filter (elastic#28225)
  Avoid doing redundant work when checking for self references. (elastic#26927)
  Fix casts in HotThreads. (elastic#27578)
  Ignore the `-snapshot` suffix when comparing the Lucene version in the build and the docs. (elastic#27927)
  Allow update of `eager_global_ordinals` on `_parent`. (elastic#28014)
  Fix NPE on composite aggregation with sub-aggregations that need scores (elastic#28129)
  `MockTcpTransport` to connect asynchronously (elastic#28203)
  Fix synonym phrase query expansion for cross_fields parsing (elastic#28045)
  Introduce elasticsearch-core jar (elastic#28191)
  elastic#28218: Update the Lucene version for 6.2.0 after backport
  upgrade to lucene 7.2.1 (elastic#28218)
  [Docs] Fix an error in painless-types.asciidoc (elastic#28221)
  Adds metadata to rewritten aggregations (elastic#28185)
  Update version of TaskInfo header serialization after backport
  TEST: Tightens file-based condition in peer-recovery
  Correct backport replica rollback to 6.2 (elastic#28181)
  Backport replica rollback to 6.2 (elastic#28181)
  Rename deleteLocalTranslog to createNewTranslog
  ...
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants