Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 57D1C200BD8 for ; Wed, 7 Dec 2016 21:02:29 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 56A40160B30; Wed, 7 Dec 2016 20:02:29 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5A284160B45 for ; Wed, 7 Dec 2016 21:02:26 +0100 (CET) Received: (qmail 86897 invoked by uid 500); 7 Dec 2016 20:02:25 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 86511 invoked by uid 99); 7 Dec 2016 20:02:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Dec 2016 20:02:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2488FDFF56; Wed, 7 Dec 2016 20:02:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: spmallette@apache.org To: commits@tinkerpop.apache.org Date: Wed, 07 Dec 2016 20:02:50 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [27/50] tinkerpop git commit: fixed a bug in Bytecode bindings where anonymous traversals were not aware of parent Bindings. The solution sorta sucks...but I don't know how else to do it. Added test cases to verify anonymous traversal binding usage. archived-at: Wed, 07 Dec 2016 20:02:29 -0000 fixed a bug in Bytecode bindings where anonymous traversals were not aware of parent Bindings. The solution sorta sucks...but I don't know how else to do it. Added test cases to verify anonymous traversal binding usage. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cba782ae Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cba782ae Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cba782ae Branch: refs/heads/TINKERPOP-1490 Commit: cba782ae2632c4e0c10fcf0131f5751a6fd61dd3 Parents: 9e82b4d Author: Marko A. Rodriguez Authored: Tue Nov 29 09:07:22 2016 -0700 Committer: Marko A. Rodriguez Committed: Tue Nov 29 09:07:22 2016 -0700 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../gremlin/process/traversal/Bytecode.java | 17 ++++++------ .../gremlin/process/traversal/BytecodeTest.java | 28 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba782ae/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 9791b64..10a0604 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima TinkerPop 3.2.4 (Release Date: NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Fixed a bug in Gremlin-Java `Bytecode` where anonymous traversals were not aware of parent bindings. * Fixed a bug in Gremlin-Java GraphSON deserialization around `P.within()` and `P.without()`. * Converted Spark process suite tests to "integration" tests. * Fixed a bug in `InlineFilterStrategy` having to do with folding `HasContainers` into `VertexStep`. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba782ae/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java index da09362..377195f 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java @@ -52,7 +52,7 @@ public final class Bytecode implements Cloneable, Serializable { private List sourceInstructions = new ArrayList<>(); private List stepInstructions = new ArrayList<>(); - private transient Bindings bindings = null; + private static transient ThreadLocal BINDINGS = new ThreadLocal<>(); /** * Add a {@link TraversalSource} instruction to the bytecode. @@ -62,8 +62,7 @@ public final class Bytecode implements Cloneable, Serializable { */ public void addSource(final String sourceName, final Object... arguments) { if (sourceName.equals(TraversalSource.Symbols.withBindings)) { - this.bindings = (Bindings) arguments[0]; - this.bindings.clear(); + BINDINGS.set((Bindings) arguments[0]); } else if (sourceName.equals(TraversalSource.Symbols.withoutStrategies)) { final Class[] classes = new Class[arguments.length]; for (int i = 0; i < arguments.length; i++) { @@ -74,8 +73,8 @@ public final class Bytecode implements Cloneable, Serializable { this.sourceInstructions.add(new Instruction(sourceName, classes)); } else { this.sourceInstructions.add(new Instruction(sourceName, flattenArguments(arguments))); - if (null != this.bindings) this.bindings.clear(); } + if (null != BINDINGS.get()) BINDINGS.get().clear(); } /** @@ -86,7 +85,7 @@ public final class Bytecode implements Cloneable, Serializable { */ public void addStep(final String stepName, final Object... arguments) { this.stepInstructions.add(new Instruction(stepName, flattenArguments(arguments))); - if (null != this.bindings) this.bindings.clear(); + if (null != BINDINGS.get()) BINDINGS.get().clear(); } /** @@ -118,9 +117,9 @@ public final class Bytecode implements Cloneable, Serializable { } /** - * Get all the bindings (in a nested, recurssive manner) from all the arguments of all the instructions of this bytecode. + * Get all the BINDINGS (in a nested, recurssive manner) from all the arguments of all the instructions of this bytecode. * - * @return a map of string variable and object value bindings + * @return a map of string variable and object value BINDINGS */ public Map getBindings() { final Map bindingsMap = new HashMap<>(); @@ -273,8 +272,8 @@ public final class Bytecode implements Cloneable, Serializable { } private final Object convertArgument(final Object argument, final boolean searchBindings) { - if (searchBindings && null != this.bindings) { - final String variable = this.bindings.getBoundVariable(argument); + if (searchBindings && null != BINDINGS.get()) { + final String variable = BINDINGS.get().getBoundVariable(argument); if (null != variable) return new Binding<>(variable, convertArgument(argument, false)); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba782ae/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java index 1b655ca..ea81bdc 100644 --- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java +++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java @@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.process.traversal; import org.apache.tinkerpop.gremlin.process.computer.Computer; import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy; @@ -30,6 +31,8 @@ import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; import org.junit.Test; +import java.util.List; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -99,6 +102,31 @@ public class BytecodeTest { } @Test + public void shouldIncludeBindingsInNestedTraversals() { + final Bindings b = new Bindings(); + final GraphTraversalSource g = EmptyGraph.instance().traversal().withBindings(b); + final Bytecode bytecode = g.V().in(b.of("a","created")).where(__.out(b.of("b","knows")).has("age",b.of("c",P.gt(32))).map(__.values(b.of("d","name")))).asAdmin().getBytecode(); + assertEquals(4, bytecode.getBindings().size()); + assertEquals("created", bytecode.getBindings().get("a")); + assertEquals("knows", bytecode.getBindings().get("b")); + assertEquals(P.gt(32), bytecode.getBindings().get("c")); + assertEquals("name", bytecode.getBindings().get("d")); + // + Bytecode.Binding binding = (Bytecode.Binding)((List)bytecode.getStepInstructions()).get(1).getArguments()[0]; + assertEquals("a", binding.variable()); + assertEquals("created", binding.value()); + binding = (Bytecode.Binding) ((List)((Bytecode)((List)bytecode.getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(0).getArguments()[0]; + assertEquals("b", binding.variable()); + assertEquals("knows", binding.value()); + binding = (Bytecode.Binding) ((List)((Bytecode)((List)bytecode.getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(1).getArguments()[1]; + assertEquals("c", binding.variable()); + assertEquals(P.gt(32), binding.value()); + binding = (Bytecode.Binding) ((List)((Bytecode)((List)((Bytecode)((List)bytecode.getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(0).getArguments()[0]; + assertEquals("d", binding.variable()); + assertEquals("name", binding.value()); + } + + @Test public void shouldConvertStrategies() { final GraphTraversalSource g = EmptyGraph.instance().traversal(); Bytecode bytecode = g.withStrategies(ReadOnlyStrategy.instance()).getBytecode();