-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Add a shallow copy method to aggregation builders #28430
Conversation
@colings86 sorry ;), I asked for help because I thought that each builder would need a specific test for the added method but BaseAggregationTestCase can |
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.
@jimczi I think it mostly looks good, my only comments are around the fields in the clone potentially being mutated and affecting the original which I think we need to protect against.
@@ -52,6 +55,10 @@ protected AggregationBuilder(String name) { | |||
this.name = name; | |||
} | |||
|
|||
protected AggregationBuilder(AggregationBuilder clone) { | |||
this.name = clone.name; |
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.
if this is supposed to produce and exact clone of the passed in builder then should we not set the factoriesBuilder here too?
protected AbstractRangeBuilder(AbstractRangeBuilder<AB, R> clone) { | ||
super(clone); | ||
this.rangeFactory = clone.rangeFactory; | ||
this.ranges = clone.ranges; |
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.
I think we might want to copy the list here rather than share it between the old and new copies? Otherwise if the builder is cloned and then addRange
is called on the copy it will also change the original?
this.distanceType = clone.distanceType; | ||
this.unit = clone.unit; | ||
this.keyed = clone.keyed; | ||
this.ranges = clone.ranges; |
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.
I think we should copy the ranges list?
@@ -222,6 +222,17 @@ public IpRangeAggregationBuilder(String name) { | |||
super(name, ValuesSourceType.BYTES, ValueType.IP); | |||
} | |||
|
|||
protected IpRangeAggregationBuilder(IpRangeAggregationBuilder clone) { | |||
super(clone); | |||
this.ranges = clone.ranges; |
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.
I think we should copy the ranges list?
@@ -129,6 +129,20 @@ public SignificantTermsAggregationBuilder(StreamInput in) throws IOException { | |||
significanceHeuristic = in.readNamedWriteable(SignificanceHeuristic.class); | |||
} | |||
|
|||
protected SignificantTermsAggregationBuilder(SignificantTermsAggregationBuilder clone) { | |||
super(clone); | |||
this.bucketCountThresholds = clone.bucketCountThresholds; |
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.
It seems that BucketCountThresholds is mutable so I think we need to clone it as well?
@@ -123,6 +123,22 @@ public AggregationBuilder parse(String aggregationName, XContentParser parser) | |||
}; | |||
} | |||
|
|||
protected SignificantTextAggregationBuilder(SignificantTextAggregationBuilder clone) { | |||
super(clone); | |||
this.bucketCountThresholds = clone.bucketCountThresholds; |
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.
It seems that BucketCountThresholds is mutable so I think we need to clone it as well?
super(clone); | ||
this.bucketCountThresholds = clone.bucketCountThresholds; | ||
this.fieldName = clone.fieldName; | ||
this.filterBuilder = clone.filterBuilder; |
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.
Is this filterBuilder potentially mutable too?
this.executionHint = clone.executionHint; | ||
this.includeExclude = clone.includeExclude; | ||
this.collectMode = clone.collectMode; | ||
this.bucketCountThresholds = clone.bucketCountThresholds; |
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.
It seems that BucketCountThresholds is mutable so I think we need to clone it as well?
this.storedFieldsContext = clone.storedFieldsContext; | ||
this.fieldDataFields = clone.fieldDataFields; | ||
this.scriptFields = clone.scriptFields; | ||
this.fetchSourceContext = clone.fetchSourceContext; |
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.
Are any of these object mutable?
64283f5
to
f1ee92a
Compare
Thanks for reviewing @colings86 . |
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.
LGTM, thanks for making the changes
This change adds a shallow copy method for aggregation builders. This method returns a copy of the builder replacing the factoriesBuilder and metaDada This method is used when the builder is rewritten (AggregationBuilder#rewrite) in order to make sure that we create a new instance of the parent builder when sub aggregations are rewritten. Relates elastic#27782
018bbea
to
238fe67
Compare
This change adds a shallow copy method for aggregation builders. This method returns a copy of the builder replacing the factoriesBuilder and metaDada This method is used when the builder is rewritten (AggregationBuilder#rewrite) in order to make sure that we create a new instance of the parent builder when sub aggregations are rewritten. Relates #27782
This commit adds a test to check that the rewrite of a sub-aggregation triggers a copy of the parent aggregation. Relates elastic#28430 Closes elastic#27782
This change adds a shallow copy method for aggregation builders. This method returns a copy of the builder replacing the factoriesBuilder and metaData.
This method is used when the builder is rewritten (AggregationBuilder#rewrite) in order to make sure that we create a new instance of the parent builder when sub aggregations are rewritten.
Relates #27782