much more elegant solution to the GroupStep.GroupBiOperator problem involving serialization --- better solution: just check for lambdas (LambdaHolder) and only check for lambdas on the child traversal.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/43d276a7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/43d276a7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/43d276a7 Branch: refs/heads/tp31 Commit: 43d276a7b9ce14d277c3b6229c61883088305175 Parents: d2eb63c Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Tue May 31 13:27:54 2016 -0600 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Tue May 31 13:27:54 2016 -0600 ---------------------------------------------------------------------- .../process/traversal/step/map/GroupStep.java | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/43d276a7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java index dd899de..1187a1a 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroupStep.java @@ -29,6 +29,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.lambda.IdentityTraversal; import org.apache.tinkerpop.gremlin.process.traversal.lambda.TokenTraversal; import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier; import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating; +import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder; import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent; import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep; import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep; @@ -37,7 +38,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSe import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; -import org.apache.tinkerpop.gremlin.util.Serializer; import org.apache.tinkerpop.gremlin.util.function.HashMapSupplier; import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; import org.javatuples.Pair; @@ -162,8 +162,14 @@ public final class GroupStep<S, K, V> extends ReducingBarrierStep<S, Map<K, V>> private Barrier barrierStep; public GroupBiOperator(final Traversal.Admin<?, V> valueTraversal) { - this.valueTraversal = valueTraversal.clone(); - this.barrierStep = TraversalHelper.getFirstStepOfAssignableClass(Barrier.class, this.valueTraversal).orElse(null); + // if there is a lambda that can not be serialized, then simply use TraverserSets + if (TraversalHelper.hasStepOfAssignableClassRecursively(LambdaHolder.class, valueTraversal)) { + this.valueTraversal = null; + this.barrierStep = null; + } else { + this.valueTraversal = valueTraversal; + this.barrierStep = TraversalHelper.getFirstStepOfAssignableClass(Barrier.class, this.valueTraversal).orElse(null); + } } public GroupBiOperator() { @@ -298,16 +304,9 @@ public final class GroupStep<S, K, V> extends ReducingBarrierStep<S, Map<K, V>> // necessary to control Java Serialization to ensure proper clearing of internal traverser data private void writeObject(final ObjectOutputStream outputStream) throws IOException { - if (null != this.valueTraversal) { - try { - // if there is a lambda that can not be serialized, then simply use TraverserSets - this.valueTraversal.setParent(EmptyStep.instance()); - Serializer.serializeObject(this.valueTraversal); - } catch (final IOException e) { - this.valueTraversal = null; - } - } - outputStream.writeObject(null == this.valueTraversal ? null : this.valueTraversal.clone()); + // necessary as a non-root child is being sent over the wire + if (null != this.valueTraversal) this.valueTraversal.setParent(EmptyStep.instance()); + outputStream.writeObject(null == this.valueTraversal ? null : this.valueTraversal.clone()); // todo: reset() instead? } private void readObject(final ObjectInputStream inputStream) throws IOException, ClassNotFoundException {