You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by va...@apache.org on 2024/06/10 16:30:13 UTC

(tinkerpop) branch valentyn/bytecode-poc updated: cleanup

This is an automated email from the ASF dual-hosted git repository.

valentyn pushed a commit to branch valentyn/bytecode-poc
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/valentyn/bytecode-poc by this push:
     new 1c46add635 cleanup
1c46add635 is described below

commit 1c46add635d42f06e0212753e4ae12782503cb4a
Author: Valentyn Kahamlyk <Va...@improving.com>
AuthorDate: Mon Jun 10 09:30:04 2024 -0700

    cleanup
---
 .../gremlin/process/traversal/Bytecode.java        | 16 ++---
 .../gremlin/process/traversal/GremlincodeTest.java | 72 +++++++++++-----------
 2 files changed, 44 insertions(+), 44 deletions(-)

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 9c6e57b1cc..a14d0f02ae 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
@@ -45,6 +45,7 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy.STRATEGY;
 import static org.apache.tinkerpop.gremlin.util.DatetimeHelper.format;
@@ -61,8 +62,8 @@ public class Bytecode implements Cloneable, Serializable {
 
     private StringBuilder gremlin = new StringBuilder();
     private Map<String, Object> parameters = new HashMap<>();
-    // private static final AtomicInteger paramCount = new AtomicInteger(0);
-    private static final ThreadLocal<Integer> paramCount = ThreadLocal.withInitial(() -> 0);
+    private static final AtomicInteger paramCount = new AtomicInteger(0);
+    // private static final ThreadLocal<Integer> paramCount = ThreadLocal.withInitial(() -> 0);
     private final List<OptionsStrategy> optionsStrategies = new ArrayList<>();
 
     public Bytecode() {
@@ -76,6 +77,7 @@ public class Bytecode implements Cloneable, Serializable {
     private void addToGremlin(final String name, final Object... arguments) {
         final Object[] flattenedArguments = flattenArguments(arguments);
 
+        // todo: figure out solution for AbstractLambdaTraversal
         if (name.equals("CardinalityValueTraversal")) {
             gremlin.append("Cardinality.").append(flattenedArguments[0])
                     .append("(").append(flattenedArguments[1]).append(")");
@@ -179,9 +181,10 @@ public class Bytecode implements Cloneable, Serializable {
             }
         }
 
-        // final String paramName = String.format("_%d", paramCount.getAndIncrement());
-        final String paramName = String.format("_%d", paramCount.get());
-        paramCount.set(paramCount.get() + 1);
+        //final String paramName = String.format("_%d", paramCount.get());
+        //paramCount.set(paramCount.get() + 1);
+        final String paramName = String.format("_%d", paramCount.getAndIncrement());
+        // todo: consider resetting paramCount when it's larger then 1_000_000
         parameters.put(paramName, arg);
         return paramName;
     }
@@ -436,9 +439,6 @@ public class Bytecode implements Cloneable, Serializable {
             clone.parameters = new HashMap<>(parameters);
             clone.gremlin = new StringBuilder(gremlin.length());
             clone.gremlin.append(gremlin);
-            // gremlincode cloned when new traversal created
-            // let's reset paramCount for easy testing. Will not work for prod usage
-            // paramCount.set(0);
             return clone;
         } catch (final CloneNotSupportedException e) {
             throw new IllegalStateException(e.getMessage(), e);
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlincodeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlincodeTest.java
index 9d96a80ad8..dd2b2cb4ab 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlincodeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlincodeTest.java
@@ -72,44 +72,44 @@ public class GremlincodeTest {
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> generateTestParameters() {
         return Arrays.asList(new Object[][]{
-//                {g.V().count(), "g.V().count()"},
-//                {g.addV("test"), "g.addV(\"test\")"},
-//                {g.addV("t\"'est"), "g.addV(\"t\\\"'est\")"},
-//                {g.inject(true, (byte) 1, (short) 2, 3, 4L, 5f, 6d), "g.inject(true,1B,2S,3,4L,5.0F,6.0D)"},
-//                {g.inject(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY),
-//                        "g.inject(+Infinity,-Infinity)"},
-//                {g.inject(DatetimeHelper.parse("2018-03-21T08:35:44.741Z")),
-//                        "g.inject(datetime(\"2018-03-21T08:35:44.741Z\"))"},
+                {g.V().count(), "g.V().count()"},
+                {g.addV("test"), "g.addV(\"test\")"},
+                {g.addV("t\"'est"), "g.addV(\"t\\\"'est\")"},
+                {g.inject(true, (byte) 1, (short) 2, 3, 4L, 5f, 6d), "g.inject(true,1B,2S,3,4L,5.0F,6.0D)"},
+                {g.inject(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY),
+                        "g.inject(+Infinity,-Infinity)"},
+                {g.inject(DatetimeHelper.parse("2018-03-21T08:35:44.741Z")),
+                        "g.inject(datetime(\"2018-03-21T08:35:44.741Z\"))"},
                 {g.inject(asMap("age", VertexProperty.Cardinality.list(33))),
                         "g.inject([\"age\":Cardinality.list(33)])"},
-//                {g.V(1).out("knows").values("name"), "g.V(1).out(\"knows\").values(\"name\")"},
-//                {g.V().has(T.label,"person"), "g.V().has(T.label,\"person\")"},
-//                {g.addE("knows").from(new DetachedVertex(1, "test1", Collections.emptyList())).to(new DetachedVertex(6, "test2", Collections.emptyList())),
-//                        "g.addE(\"knows\").from(new ReferenceVertex(1,\"test1\")).to(new ReferenceVertex(6,\"test2\"))"}
-//                {g.V().hasId(P.within(Collections.emptyList())).count(), "g.V().hasId(P.within(_0)).count()"},
-//                {g.V(1).outE().has("weight", P.inside(0.0, 0.6)), "g.V(1).outE().has(\"weight\",P.gt(0.0D).and(P.lt(0.6D)))"}
-//                {g.withSack(1.0, Operator.sum).V(1).local(__.out("knows").barrier(SackFunctions.Barrier.normSack)).in("knows").barrier().sack(),
-//                    "g.withSack(1.0D,Operator.sum).V(1).local(__.out(\"knows\").barrier(Barrier.normSack)).in(\"knows\").barrier().sack()"}
-//                {g.inject(Arrays.asList(1, 2, 3)).skip(local, 1), "g.inject(_0).skip(Scope.local,1L)"},
-//                {g.V().has("name", "marko").
-//                        project("name", "friendsNames").
-//                        by("name").
-//                        by(out("knows").values("name").fold()),
-//                        "g.V().has(\"name\",\"marko\")." +
-//                                "project(\"name\",\"friendsNames\")." +
-//                                "by(\"name\")." +
-//                                "by(__.out(\"knows\").values(\"name\").fold())"},
-//                {g.inject(Arrays.asList(5, 6)).union(__.V(Arrays.asList(1, 2)), __.V(Arrays.asList(3, 4))),
-//                        "g.inject(_0).union(__.V(_1),__.V(_2))"},
-//                {g.with("evaluationTimeout", 1000).V(), "g.V()"},
-//                { g.withSideEffect("a", 1).V(), "g.withSideEffect(\"a\",1).V()"}
-//                {g.withStrategies(ReadOnlyStrategy.instance()).V(), "g.withStrategies(ReadOnlyStrategy).V()"},
-//                {g.withStrategies(new SeedStrategy(999999)).V().order().by("name").coin(0.5),
-//                        "g.withStrategies(new SeedStrategy(seed:999999L)).V().order().by(\"name\").coin(0.5D)"}
-//                    {g.withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()).V(),
-//                        "g.withStrategies(new SubgraphStrategy(checkAdjacentVertices:true,vertices:_0)).V()", },
-//                {g.withStrategies(SubgraphStrategy.build().vertices(__.has("name", P.within("josh", "lop", "ripple"))).create()).V(),
-//                        "g.withStrategies(new SubgraphStrategy(checkAdjacentVertices:true,vertices:__.has(\"name\",P.within(_0)))).V()"},
+                {g.V(1).out("knows").values("name"), "g.V(1).out(\"knows\").values(\"name\")"},
+                {g.V().has(T.label, "person"), "g.V().has(T.label,\"person\")"},
+                {g.addE("knows").from(new DetachedVertex(1, "test1", Collections.emptyList())).to(new DetachedVertex(6, "test2", Collections.emptyList())),
+                        "g.addE(\"knows\").from(new ReferenceVertex(1,\"test1\")).to(new ReferenceVertex(6,\"test2\"))"},
+                {g.V().hasId(P.within(Collections.emptyList())).count(), "g.V().hasId(P.within(_0)).count()"},
+                {g.V(1).outE().has("weight", P.inside(0.0, 0.6)), "g.V(1).outE().has(\"weight\",P.gt(0.0D).and(P.lt(0.6D)))"},
+                {g.withSack(1.0, Operator.sum).V(1).local(__.out("knows").barrier(SackFunctions.Barrier.normSack)).in("knows").barrier().sack(),
+                        "g.withSack(1.0D,Operator.sum).V(1).local(__.out(\"knows\").barrier(Barrier.normSack)).in(\"knows\").barrier().sack()"},
+                {g.inject(Arrays.asList(1, 2, 3)).skip(local, 1), "g.inject(_1).skip(Scope.local,1L)"},
+                {g.V().has("name", "marko").
+                        project("name", "friendsNames").
+                        by("name").
+                        by(out("knows").values("name").fold()),
+                        "g.V().has(\"name\",\"marko\")." +
+                                "project(\"name\",\"friendsNames\")." +
+                                "by(\"name\")." +
+                                "by(__.out(\"knows\").values(\"name\").fold())"},
+                {g.inject(Arrays.asList(5, 6)).union(__.V(Arrays.asList(1, 2)), __.V(Arrays.asList(3, 4))),
+                        "g.inject(_2).union(__.V(_3),__.V(_4))"},
+                {g.with("evaluationTimeout", 1000).V(), "g.V()"},
+                {g.withSideEffect("a", 1).V(), "g.withSideEffect(\"a\",1).V()"},
+                {g.withStrategies(ReadOnlyStrategy.instance()).V(), "g.withStrategies(ReadOnlyStrategy).V()"},
+                {g.withStrategies(new SeedStrategy(999999)).V().order().by("name").coin(0.5),
+                        "g.withStrategies(new SeedStrategy(seed:999999L)).V().order().by(\"name\").coin(0.5D)"},
+                {g.withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()).V(),
+                        "g.withStrategies(new SubgraphStrategy(checkAdjacentVertices:true,vertices:__.hasLabel(\"person\"))).V()",},
+                {g.withStrategies(SubgraphStrategy.build().vertices(__.has("name", P.within("josh", "lop", "ripple"))).create()).V(),
+                        "g.withStrategies(new SubgraphStrategy(checkAdjacentVertices:true,vertices:__.has(\"name\",P.within(_5)))).V()"},
         });
     }
 }