Cole-Greer commented on code in PR #3209:
URL: https://github.com/apache/tinkerpop/pull/3209#discussion_r2373558959
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractMergeElementStepPlaceholder.java:
##########
@@ -65,14 +67,67 @@ protected Traverser.Admin<E> processNextStart() throws
NoSuchElementException {
@Override
public AbstractMergeElementStepPlaceholder<S, E> clone() {
- return (AbstractMergeElementStepPlaceholder<S, E>) super.clone();
+ AbstractMergeElementStepPlaceholder<S, E> clone =
(AbstractMergeElementStepPlaceholder<S, E>) super.clone();
+ if (mergeTraversal != null){
+ clone.setMerge(mergeTraversal.clone());
+ }
+ if (onMatchTraversal != null) {
+ clone.setOnMatch(onMatchTraversal.clone());
+ }
+ if (onCreateTraversal != null) {
+ clone.setOnCreate(onCreateTraversal.clone());
+ }
+
+ // deep clone properties
+ clone.properties = new HashMap<>();
+ for (Map.Entry<Object, List<Object>> entry :
this.properties.entrySet()) {
+ final Object key = entry.getKey();
+ final List<Object> oldValues = entry.getValue();
+ final List<Object> newValues = new ArrayList<>(oldValues.size());
+ for (Object v : oldValues) {
+ if (v instanceof Traversal) {
+ newValues.add(((Traversal<?, ?>) v).asAdmin().clone());
+ } else if (v instanceof GValue) {
+ try {
+ newValues.add(((GValue) v).clone());
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ newValues.add(v);
+ }
+ }
+ clone.properties.put(key, newValues);
+ }
+ return clone;
}
@Override
public Set<TraverserRequirement> getRequirements() {
return super.getRequirements();
}
+ @Override
+ public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) {
+ super.setTraversal(parentTraversal);
+ this.getLocalChildren().forEach(this::integrateChild);
Review Comment:
Every child traversal needs to be integrated when it's added to the step.
Within the constructor, the only child traversal present is `mergeTraversal`,
which gets integrated in the constructor. Any calls to `setOnMatch()`,
`setOnCreate()`, or `setMerge()` result in integrating the newly added child
traversal.
When `setTraversal()` is called, `this` step is being assigned a new parent,
and we need to re-integrate all children such that their side effects and
GValueManagers are synced with the new parent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]