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

[01/13] tinkerpop git commit: first non-tested implementation of math()-step. It uses the @twilmes model which parses a String representation of the expression. [Forced Update!]

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1799 74c617b08 -> d5ed2f7cb (forced update)


first non-tested implementation of math()-step. It uses the @twilmes model which parses a String representation of the expression.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6f1a1f70
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6f1a1f70
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6f1a1f70

Branch: refs/heads/TINKERPOP-1799
Commit: 6f1a1f7028f285c6e45b7e7596320710b91114c5
Parents: 4728916
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Oct 3 17:37:10 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Oct 3 17:37:10 2017 -0600

----------------------------------------------------------------------
 gremlin-core/pom.xml                            |   5 +
 .../traversal/dsl/graph/GraphTraversal.java     |  14 ++
 .../gremlin/process/traversal/dsl/graph/__.java |   7 +
 .../process/traversal/step/map/MathStep.java    | 128 +++++++++++++++++++
 .../process/traversal/util/TraversalHelper.java |   2 +-
 .../traversal/dsl/graph/GraphTraversalTest.java |   2 +
 .../Process/Traversal/GraphTraversal.cs         |   9 ++
 .../src/Gremlin.Net/Process/Traversal/__.cs     |   8 ++
 .../gremlin_python/process/graph_traversal.py   |  12 ++
 .../structure/TinkerGraphPlayTest.java          |  42 +-----
 10 files changed, 188 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index 3d9e701..30c1b9f 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -68,6 +68,11 @@ limitations under the License.
             <artifactId>javapoet</artifactId>
             <version>1.8.0</version>
         </dependency>
+        <dependency>
+            <groupId>net.objecthunter</groupId>
+            <artifactId>exp4j</artifactId>
+            <version>0.4.8</version>
+        </dependency>
         <!-- LOGGING -->
         <dependency>
             <groupId>org.slf4j</groupId>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 44a7a3a..8cedbfb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -86,6 +86,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.LambdaFlatMapStep
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.LambdaMapStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.LoopsStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MathStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxLocalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanGlobalStep;
@@ -1097,6 +1098,18 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
         return this;
     }
 
+    /**
+     * Map the {@link Traverser} to a {@link Double} according to the mathematical expression provided in the argument.
+     *
+     * @param expression the mathematical expression with variables refering to scope variables.
+     * @return the traversal with the {@link MathStep} added.
+     * @since 3.3.1
+     */
+    public default GraphTraversal<S, Double> math(final String expression) {
+        this.asAdmin().getBytecode().addStep(Symbols.math, expression);
+        return this.asAdmin().addStep(new MathStep<>(this.asAdmin(), expression));
+    }
+
     ///////////////////// FILTER STEPS /////////////////////
 
     /**
@@ -2691,6 +2704,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
         public static final String value = "value";
         public static final String path = "path";
         public static final String match = "match";
+        public static final String math = "math";
         public static final String sack = "sack";
         public static final String loops = "loops";
         public static final String project = "project";

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index 9dc3a93..39e5258 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -498,6 +498,13 @@ public class __ {
         return __.<A>start().addE(edgeLabelTraversal);
     }
 
+    /**
+     * @see GraphTraversal#math(String)
+     */
+    public static <A> GraphTraversal<A, Double> math(final String expression) {
+        return __.<A>start().math(expression);
+    }
+
     ///////////////////// FILTER STEPS /////////////////////
 
     /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
new file mode 100644
index 0000000..645ea06
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -0,0 +1,128 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import net.objecthunter.exp4j.Expression;
+import net.objecthunter.exp4j.ExpressionBuilder;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class MathStep<S> extends MapStep<S, Double> implements ByModulating, TraversalParent, Scoping {
+
+    private static final String CURRENT = "_";
+    private final String equation;
+    private final Set<String> variables;
+    private final Expression expression;
+    private TraversalRing<Object, Number> traversalRing = new TraversalRing<>();
+
+    public MathStep(final Traversal.Admin traversal, final String equation) {
+        super(traversal);
+        this.equation = equation;
+        final Set<String> labels = TraversalHelper.getLabels(TraversalHelper.getRootTraversal(this.getTraversal()));
+        this.variables = new LinkedHashSet<>();
+        for (final String label : labels) {
+            if (this.equation.contains(label))
+                this.variables.add(label);
+        }
+        if (this.equation.contains(CURRENT))
+            this.variables.add(CURRENT);
+        this.expression = new ExpressionBuilder(this.equation)
+                .variables(this.variables)
+                .build();
+    }
+
+    @Override
+    protected Double map(final Traverser.Admin<S> traverser) {
+        for (final String var : this.variables) {
+            this.expression.setVariable(var, TraversalUtil.applyNullable(
+                    var.equals(CURRENT) ?
+                            traverser.get() :
+                            this.getNullableScopeValue(Pop.last, var, traverser),
+                    this.traversalRing.next()).doubleValue());
+        }
+        this.traversalRing.reset();
+        return this.expression.evaluate();
+    }
+
+    @Override
+    public void modulateBy(final Traversal.Admin<?, ?> selectTraversal) {
+        this.traversalRing.addTraversal(this.integrateChild(selectTraversal));
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.stepString(this, this.equation, this.traversalRing);
+    }
+
+    @Override
+    public int hashCode() {
+        return super.hashCode() ^ this.equation.hashCode() ^ this.traversalRing.hashCode();
+    }
+
+    @Override
+    public List<Traversal.Admin<Object, Number>> getLocalChildren() {
+        return this.traversalRing.getTraversals();
+    }
+
+    @Override
+    public void reset() {
+        super.reset();
+        this.traversalRing.reset();
+    }
+
+    @Override
+    public MathStep<S> clone() {
+        final MathStep<S> clone = (MathStep<S>) super.clone();
+        clone.traversalRing = this.traversalRing.clone();
+        return clone;
+    }
+
+    @Override
+    public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) {
+        super.setTraversal(parentTraversal);
+        this.traversalRing.getTraversals().forEach(this::integrateChild);
+    }
+
+    @Override
+    public Set<TraverserRequirement> getRequirements() {
+        return this.getSelfAndChildRequirements(TraverserRequirement.OBJECT, TraverserRequirement.SIDE_EFFECTS);
+    }
+
+    @Override
+    public Set<String> getScopeKeys() {
+        return this.variables;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index 56f2eca..9db3ea8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -560,7 +560,7 @@ public final class TraversalHelper {
     }
 
     public static Set<String> getLabels(final Traversal.Admin<?, ?> traversal) {
-        return TraversalHelper.getLabels(new HashSet<>(), traversal);
+        return TraversalHelper.getLabels(new LinkedHashSet<>(), traversal);
     }
 
     private static Set<String> getLabels(final Set<String> labels, final Traversal.Admin<?, ?> traversal) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java
index cfa63fa..d3fe1c4 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java
@@ -112,6 +112,8 @@ public class GraphTraversalTest {
                         list.add(arguments[0] = (long) (Math.abs(random.nextInt(10))));
                         list.add(arguments[1] = (long) (Math.abs(random.nextInt(10) + 100)));
                     }
+                } else if (stepMethod.getName().equals("math")) {
+                    list.add(arguments[0] = random.nextInt(100) + " + " + random.nextInt(100));
                 } else {
                     for (int i = 0; i < stepMethod.getParameterTypes().length; i++) {
                         final Class<?> type = stepMethod.getParameterTypes()[i];

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
index 00bfd4b..6c6d174 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
@@ -495,6 +495,15 @@ namespace Gremlin.Net.Process.Traversal
         }
 
         /// <summary>
+        ///     Adds the math step to this <see cref="GraphTraversal{SType, EType}" />.
+        /// </summary>
+        public GraphTraversal< S , Double > Math (params object[] args)
+        {
+            Bytecode.AddStep("math", args);
+            return Wrap< S , Double >(this);
+        }
+
+        /// <summary>
         ///     Adds the max step to this <see cref="GraphTraversal{SType, EType}" />.
         /// </summary>
         public GraphTraversal< S , E2 > Max<E2> (params object[] args)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs
index dfe114d..0e0c527 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs
@@ -409,6 +409,14 @@ namespace Gremlin.Net.Process.Traversal
         }
 
         /// <summary>
+        ///     Spawns a <see cref="GraphTraversal{SType, EType}" /> and adds the math step to that traversal.
+        /// </summary>
+        public static GraphTraversal<object, Double> Math(params object[] args)
+        {
+            return new GraphTraversal<object, object>().Math(args);
+        }
+
+        /// <summary>
         ///     Spawns a <see cref="GraphTraversal{SType, EType}" /> and adds the max step to that traversal.
         /// </summary>
         public static GraphTraversal<object, E2> Max<E2>(params object[] args)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index f7bb201..d5630c0 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -317,6 +317,10 @@ class GraphTraversal(Traversal):
         self.bytecode.add_step("match", *args)
         return self
 
+    def math(self, *args):
+        self.bytecode.add_step("math", *args)
+        return self
+
     def max(self, *args):
         self.bytecode.add_step("max", *args)
         return self
@@ -697,6 +701,10 @@ class __(object):
         return cls.graph_traversal(None, None, Bytecode()).match(*args)
 
     @classmethod
+    def math(cls, *args):
+        return cls.graph_traversal(None, None, Bytecode()).math(*args)
+
+    @classmethod
     def max(cls, *args):
         return cls.graph_traversal(None, None, Bytecode()).max(*args)
 
@@ -1046,6 +1054,10 @@ def match(*args):
     return __.match(*args)
 statics.add_static('match', match)
 
+def math(*args):
+    return __.math(*args)
+statics.add_static('math', math)
+
 def max(*args):
     return __.max(*args)
 statics.add_static('max', max)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1a1f70/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index eeb4f38..0af81bd 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -50,6 +50,7 @@ import static org.apache.tinkerpop.gremlin.process.traversal.P.lt;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.choose;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
@@ -70,48 +71,9 @@ public class TinkerGraphPlayTest {
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
         GraphTraversalSource g = graph.traversal();
-
-        final Traversal<?, ?> traversal = g.V().repeat(out()).times(2).groupCount().by("name").select(Column.keys).order().by(Order.decr);
-        final Bytecode bytecode = traversal.asAdmin().getBytecode();
-        //final JavaTranslator translator = JavaTranslator.of(g);
-        final Map<Bytecode, Traversal.Admin<?, ?>> cache = new HashMap<>();
-        cache.put(bytecode, traversal.asAdmin());
-        final HashSet<?> result = new LinkedHashSet<>(Arrays.asList("ripple", "lop"));
-
-        System.out.println("BYTECODE: " + bytecode + "\n");
-        System.out.println("Bytecode->Traversal.clone() cache: " + TimeUtil.clock(1000, () -> {
-            final Traversal.Admin<?, ?> t = cache.get(bytecode).clone();
-            //assertEquals(result, t.next());
-        }));
-
-        System.out.println("Bytecode->JavaTranslator call    : " + TimeUtil.clock(1000, () -> {
-            final Traversal t = JavaTranslator.of(g).translate(bytecode);
-            //assertEquals(result, t.next());
-        }));
-
-        System.out.println("\n==Second test with reversed execution==\n");
-
-        System.out.println("BYTECODE: " + bytecode + "\n");
-        System.out.println("Bytecode->JavaTranslator call    : " + TimeUtil.clock(1000, () -> {
-            final Traversal t = JavaTranslator.of(g).translate(bytecode);
-            //assertEquals(result, t.next());
-        }));
-
-        System.out.println("Bytecode->Traversal.clone() cache: " + TimeUtil.clock(1000, () -> {
-            final Traversal.Admin<?, ?> t = cache.get(bytecode).clone();
-            //assertEquals(result, t.next());
-        }));
+        System.out.println(g.V().as("a").out("knows").math("((a ^ _) / a)").by("age").by(bothE().count()).toList());
     }
 
-   /* @Test
-    public void testTraversalDSL() throws Exception {
-        Graph g = TinkerFactory.createClassic();
-        assertEquals(2, g.of(TinkerFactory.SocialTraversal.class).people("marko").knows().name().toList().size());
-        g.of(TinkerFactory.SocialTraversal.class).people("marko").knows().name().forEachRemaining(name -> assertTrue(name.equals("josh") || name.equals("vadas")));
-        assertEquals(1, g.of(TinkerFactory.SocialTraversal.class).people("marko").created().name().toList().size());
-        g.of(TinkerFactory.SocialTraversal.class).people("marko").created().name().forEachRemaining(name -> assertEquals("lop", name));
-    }*/
-
     @Test
     @Ignore
     public void benchmarkStandardTraversals() throws Exception {


[04/13] tinkerpop git commit: added MathStepTest to test hashCode() and the custom variable finder. Found a couple of problems in my parser and I fixed them. Forgot to make MathStep a PathProcessor so that OLAP is smart about data access. Both OLTP and O

Posted by sp...@apache.org.
added MathStepTest to test hashCode() and the custom variable finder. Found a couple of problems in my parser and I fixed them. Forgot to make MathStep a PathProcessor so that OLAP is smart about data access. Both OLTP and OLAP tests pass.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/dfddccaa
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/dfddccaa
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/dfddccaa

Branch: refs/heads/TINKERPOP-1799
Commit: dfddccaaa85898e046e6b7a5bd81da3d94777d7d
Parents: c36493b
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 11:01:53 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 11:01:53 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MathStep.java    | 47 ++++++++++++----
 .../traversal/step/map/MathStepTest.java        | 58 ++++++++++++++++++++
 .../structure/TinkerGraphPlayTest.java          |  2 +-
 3 files changed, 95 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dfddccaa/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
index ef88aac..6dd5338 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -21,10 +21,12 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 
 import net.objecthunter.exp4j.Expression;
 import net.objecthunter.exp4j.ExpressionBuilder;
+import org.apache.commons.lang.StringUtils;
 import org.apache.tinkerpop.gremlin.process.traversal.Pop;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating;
+import org.apache.tinkerpop.gremlin.process.traversal.step.PathProcessor;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
@@ -32,6 +34,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -39,35 +42,41 @@ import java.util.Set;
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
-public final class MathStep<S> extends MapStep<S, Double> implements ByModulating, TraversalParent, Scoping {
+public final class MathStep<S> extends MapStep<S, Double> implements ByModulating, TraversalParent, Scoping, PathProcessor {
 
     private static final String CURRENT = "_";
     private final String equation;
     private final Set<String> variables;
-    private final Expression expression;
     private TraversalRing<Object, Number> traversalRing = new TraversalRing<>();
+    private Set<String> keepLabels;
 
     public MathStep(final Traversal.Admin traversal, final String equation) {
         super(traversal);
         this.equation = equation;
         this.variables = MathStep.getVariables(this.equation);
-        this.expression = new ExpressionBuilder(this.equation)
-                .variables(this.variables)
-                .implicitMultiplication(false)
-                .build();
+
+    }
+
+    @Override
+    protected Traverser.Admin<Double> processNextStart() {
+        return PathProcessor.processTraverserPathLabels(super.processNextStart(), this.keepLabels);
     }
 
     @Override
     protected Double map(final Traverser.Admin<S> traverser) {
+        final Expression expression = new ExpressionBuilder(this.equation)
+                .variables(this.variables)
+                .implicitMultiplication(false)
+                .build();
         for (final String var : this.variables) {
-            this.expression.setVariable(var, TraversalUtil.applyNullable(
+            expression.setVariable(var, TraversalUtil.applyNullable(
                     var.equals(CURRENT) ?
                             traverser.get() :
                             this.getNullableScopeValue(Pop.last, var, traverser),
                     this.traversalRing.next()).doubleValue());
         }
         this.traversalRing.reset();
-        return this.expression.evaluate();
+        return expression.evaluate();
     }
 
     @Override
@@ -116,10 +125,15 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
 
     @Override
     public Set<String> getScopeKeys() {
-        return this.variables;
+        if (this.variables.contains(CURRENT)) {
+            final Set<String> temp = new HashSet<>(this.variables);
+            temp.remove(CURRENT);
+            return temp;
+        } else
+            return this.variables;
     }
 
-    private static final Set<String> getVariables(final String equation) {
+    protected static final Set<String> getVariables(final String equation) {
         final StringBuilder builder = new StringBuilder();
         final char[] chars = equation.toCharArray();
         for (int i = 0; i < chars.length; i++) {
@@ -132,7 +146,8 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
         }
         final Set<String> variables = new LinkedHashSet<>();
         for (final String slot : builder.toString().split(" ")) {
-            if (!slot.trim().isEmpty() && !slot.equals("abs") && !slot.equals("acos") &&
+            if (!slot.trim().isEmpty() && !StringUtils.isNumeric(slot) &&
+                    !slot.equals("abs") && !slot.equals("acos") &&
                     !slot.equals("asin") && !slot.equals("atan") && !slot.equals("cbrt") &&
                     !slot.equals("ceil") && !slot.equals("cos") && !slot.equals("cosh") &&
                     !slot.equals("exp") && !slot.equals("floor") && !slot.equals("log") &&
@@ -143,4 +158,14 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
         }
         return variables;
     }
+
+    @Override
+    public void setKeepLabels(final Set<String> labels) {
+        this.keepLabels = labels;
+    }
+
+    @Override
+    public Set<String> getKeepLabels() {
+        return this.keepLabels;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dfddccaa/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
new file mode 100644
index 0000000..334a367
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class MathStepTest extends StepTest {
+
+    @Override
+    protected List<Traversal> getTraversals() {
+        return Arrays.asList(
+                __.math("a+b"),
+                __.math("a+b").by("age"),
+                __.math("a/b").by("age"),
+                __.math("a+b").by("age").by(both().count()),
+                __.math("sin a + b")
+        );
+    }
+
+    @Test
+    public void shouldParseVariablesCorrectly() {
+        assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / 2")));
+        assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / sin 2")));
+        assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z")));
+        assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z + b + a")));
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dfddccaa/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 736b146..2fb0d68 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -71,7 +71,7 @@ public class TinkerGraphPlayTest {
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
         GraphTraversalSource g = graph.traversal();
-        System.out.println(g.V().values("age").toList());
+        System.out.println(g.V().values("age").math("sin _").toList());
     }
 
     @Test


[13/13] tinkerpop git commit: TINKERPOP-1799 Fixed serialization of Path objects for python.

Posted by sp...@apache.org.
TINKERPOP-1799 Fixed serialization of Path objects for python.

This issue only related to GraphSON 3.0 and was fairly straightforward to fix. Tests did not pick up the failure because they continued to use GraphSON 2.0 format in the test itself.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d5ed2f7c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d5ed2f7c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d5ed2f7c

Branch: refs/heads/TINKERPOP-1799
Commit: d5ed2f7cb9a110453667be0b1dbfc6bf9c0383a6
Parents: 0a183f8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Oct 13 12:34:42 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Oct 13 12:37:42 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                           | 1 +
 docs/src/upgrade/release-3.3.x.asciidoc                      | 8 ++++++++
 .../main/jython/gremlin_python/structure/io/graphsonV3d0.py  | 4 +---
 .../src/main/jython/tests/structure/io/test_graphsonV3d0.py  | 2 +-
 4 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d5ed2f7c/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f948391..07ce7b2 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 This release also includes changes from <<release-3-2-7, 3.2.7>>.
 
+* Fixed bug in serialization of `Path` for GraphSON 3.0 in `gremlin-python`.
 * Added support for GraphSON 3.0 in Gremlin.Net.
 * Added `math()`-step which supports scientific calculator capabilities for numbers within a traversal.
 * Added missing `GraphTraversalSource.addE()`-method to `GremlinDslProcessor`.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d5ed2f7c/docs/src/upgrade/release-3.3.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index e36bdf1..80aff8b 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -29,6 +29,14 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.3.1/CHANGELOG.asc
 
 === Upgrading for Users
 
+==== Gremlin Python path()
+
+There was a bug in GraphSON 3.0 serialization that prevented proper handling of results contain `Path` object. As a
+result, traversals that used and returned results from the `path()` step in Python would return unusable results,
+but did not actually cause an exception condition. This problem is now resolved.
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1799[TINKERPOP-1799]
+
 ==== Added `math()`-step for Scientific Traversal Computing
 
 `GraphTraversal.math(String)` was added. This step provides scientific calculator capabilities to a Gremlin traversal.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d5ed2f7c/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
index 7194f48..6b5144e 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
@@ -465,6 +465,4 @@ class PathDeserializer(_GraphSONTypeIO):
 
     @classmethod
     def objectify(cls, d, reader):
-        labels = [set(label) for label in d["labels"]]
-        objects = [reader.toObject(o) for o in d["objects"]]
-        return Path(labels, objects)
+        return Path(reader.toObject(d["labels"]), reader.toObject(d["objects"]))

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d5ed2f7c/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
index b4dfcac..d04db13 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
@@ -143,7 +143,7 @@ class TestGraphSONReader(object):
 
     def test_path(self):
         path = self.graphson_reader.readObject(
-            """{"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}},"lop"]}}"""
+            """{"@type":"g:Path","@value":{"labels":{"@type":"g:List","@value":[{"@type":"g:Set","@value":["a"]},{"@type":"g:Set","@value":["b","c"]},{"@type":"g:Set","@value":[]}]},"objects":{"@type":"g:List","@value":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}},"lop"]}}}"""
         )
         assert isinstance(path, Path)
         if six.PY3:


[09/13] tinkerpop git commit: added a test case for 6.67e−11 notation. passed.

Posted by sp...@apache.org.
added a test case for 6.67e−11 notation. passed.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/14a25432
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/14a25432
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/14a25432

Branch: refs/heads/TINKERPOP-1799
Commit: 14a254320bbe242cc83015369cbd24cd3aa14165
Parents: 2288b96
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 13:41:51 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 13:41:51 2017 -0600

----------------------------------------------------------------------
 .../gremlin/process/traversal/step/map/MathStepTest.java          | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/14a25432/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
index 85464e9..eea624f 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
@@ -49,8 +50,10 @@ public class MathStepTest extends StepTest {
 
     @Test
     public void shouldParseVariablesCorrectly() {
+        assertEquals(Collections.emptyList(), new ArrayList<>(MathStep.getVariables("1 + 2")));
         assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / 2")));
         assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / sin 2")));
+        assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / sin (2 + 6.67e−11)")));
         assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z")));
         assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z + b + a")));
         assertEquals(Arrays.asList("a_ASDF", "b", "_", "x", "z", "a"), new ArrayList<>(MathStep.getVariables("(a_ASDF + b / _) + log2 (x^3)^z + b + a")));


[10/13] tinkerpop git commit: fixed a bug in typing which caused a different applyNullable to be called. Added a nested sack() test to MathTest to verify proper sinusoidal behavior.

Posted by sp...@apache.org.
fixed a bug in typing which caused a different applyNullable to be called. Added a nested sack() test to MathTest to verify proper sinusoidal behavior.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e9664229
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e9664229
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e9664229

Branch: refs/heads/TINKERPOP-1799
Commit: e9664229038e87d9974971fb0249ad0f884a22ff
Parents: 14a2543
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 16:58:09 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 16:58:09 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MathStep.java    | 11 ++++-----
 .../process/traversal/step/map/MathTest.java    | 24 ++++++++++++++++++++
 .../structure/TinkerGraphPlayTest.java          | 15 ++++--------
 3 files changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9664229/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
index 53abc30..a10ec5e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -48,7 +48,7 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
     private static final String CURRENT = "_";
     private final String equation;
     private final Set<String> variables;
-    private TraversalRing<Object, Number> traversalRing = new TraversalRing<>();
+    private TraversalRing<S, Number> traversalRing = new TraversalRing<>();
     private Set<String> keepLabels;
 
     public MathStep(final Traversal.Admin traversal, final String equation) {
@@ -70,11 +70,10 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
                 .implicitMultiplication(false)
                 .build();
         for (final String var : this.variables) {
-            expression.setVariable(var, TraversalUtil.applyNullable(
+            expression.setVariable(var,
                     var.equals(CURRENT) ?
-                            traverser.get() :
-                            this.getNullableScopeValue(Pop.last, var, traverser),
-                    this.traversalRing.next()).doubleValue());
+                            TraversalUtil.applyNullable(traverser, this.traversalRing.next()).doubleValue() :
+                            TraversalUtil.applyNullable((S) this.getNullableScopeValue(Pop.last, var, traverser), this.traversalRing.next()).doubleValue());
         }
         this.traversalRing.reset();
         return expression.evaluate();
@@ -96,7 +95,7 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
     }
 
     @Override
-    public List<Traversal.Admin<Object, Number>> getLocalChildren() {
+    public List<Traversal.Admin<S, Number>> getLocalChildren() {
         return this.traversalRing.getTraversals();
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9664229/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
index 94065e9..9858d28 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
@@ -23,14 +23,19 @@ import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import java.util.Arrays;
+import java.util.function.BiFunction;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.process.traversal.Operator.sum;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.sack;
+import static org.junit.Assert.assertEquals;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -44,6 +49,8 @@ public abstract class MathTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Double> get_g_V_asXaX_outXcreatedX_asXbX_mathXb_plus_aX_byXinXcreatedX_countX_byXageX();
 
+    public abstract Traversal<Integer, Double> get_g_withSackX1X_injectX1X_repeatXsackXsumX_byXconstantX1XXX_timesX5X_emit_mathXsin__X_byXsackX();
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_asXaX_outXknowsX_asXbX_mathXa_plus_bX_byXageX() {
@@ -68,6 +75,18 @@ public abstract class MathTest extends AbstractGremlinProcessTest {
         checkResults(Arrays.asList(32.0d, 33.0d, 35.0d, 38.0d), traversal);
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_withSackX1X_injectX1X_repeatXsackXsumX_byXconstantX1XXX_timesX5X_emit_mathXsin__X_byXsackX() {
+        final Traversal<Integer, Double> traversal = get_g_withSackX1X_injectX1X_repeatXsackXsumX_byXconstantX1XXX_timesX5X_emit_mathXsin__X_byXsackX();
+        printTraversalForm(traversal);
+        assertEquals(0.9092974268256817d, traversal.next(), 0.01d);
+        assertEquals(0.1411200080598672d, traversal.next(), 0.01d);
+        assertEquals(-0.7568024953079282d, traversal.next(), 0.01d);
+        assertEquals(-0.9589242746631385d, traversal.next(), 0.01d);
+        assertEquals(-0.27941549819892586d, traversal.next(), 0.01d);
+    }
+
     public static class Traversals extends MathTest {
 
         @Override
@@ -84,5 +103,10 @@ public abstract class MathTest extends AbstractGremlinProcessTest {
         public Traversal<Vertex, Double> get_g_V_asXaX_outXcreatedX_asXbX_mathXb_plus_aX_byXinXcreatedX_countX_byXageX() {
             return g.V().as("a").out("created").as("b").math("b + a").by(in("created").count()).by("age");
         }
+
+        @Override
+        public Traversal<Integer, Double> get_g_withSackX1X_injectX1X_repeatXsackXsumX_byXconstantX1XXX_timesX5X_emit_mathXsin__X_byXsackX() {
+            return g.withSack(1).inject(1).repeat(__.sack((BiFunction) sum).by(__.constant(1))).times(10).emit().math("sin _").by(sack());
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e9664229/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 2fb0d68..a13a4ad 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -18,16 +18,13 @@
  */
 package org.apache.tinkerpop.gremlin.tinkergraph.structure;
 
-import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
 import org.apache.tinkerpop.gremlin.process.computer.Computer;
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 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.optimization.PathRetractionStrategy;
-import org.apache.tinkerpop.gremlin.structure.Column;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -39,23 +36,21 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Map;
+import java.util.function.BiFunction;
 import java.util.function.Supplier;
 
+import static org.apache.tinkerpop.gremlin.process.traversal.Operator.sum;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.lt;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.choose;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.sack;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.union;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
@@ -71,7 +66,7 @@ public class TinkerGraphPlayTest {
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
         GraphTraversalSource g = graph.traversal();
-        System.out.println(g.V().values("age").math("sin _").toList());
+        System.out.println(g.withSack(1).inject(1).repeat(__.sack((BiFunction)sum).by(__.constant(1))).times(10).emit().math("sin _").by(sack()).toList());
     }
 
     @Test


[02/13] tinkerpop git commit: I wrote a small parser that is able to extract variables from an exp4j equation. So far, it is pretty durable. This is a much cleaner way of determining variables than via label, side-effect, and map analysis. However, this

Posted by sp...@apache.org.
I wrote a small parser that is able to extract variables from an exp4j equation. So far, it is pretty durable. This is a much cleaner way of determining variables than via label, side-effect, and map analysis. However, this means that the by()-modulations are with respects to the order in which the variables are contained in the equation.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/624a8d70
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/624a8d70
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/624a8d70

Branch: refs/heads/TINKERPOP-1799
Commit: 624a8d706e150cc15dc2412d66d3ac9a61b90682
Parents: 6f1a1f7
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 10:27:48 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 10:27:48 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MathStep.java    | 35 +++++++++++++++-----
 .../structure/TinkerGraphPlayTest.java          |  2 +-
 2 files changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/624a8d70/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
index 645ea06..aec395c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -28,7 +28,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -51,14 +50,7 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
     public MathStep(final Traversal.Admin traversal, final String equation) {
         super(traversal);
         this.equation = equation;
-        final Set<String> labels = TraversalHelper.getLabels(TraversalHelper.getRootTraversal(this.getTraversal()));
-        this.variables = new LinkedHashSet<>();
-        for (final String label : labels) {
-            if (this.equation.contains(label))
-                this.variables.add(label);
-        }
-        if (this.equation.contains(CURRENT))
-            this.variables.add(CURRENT);
+        this.variables = MathStep.getVariables(this.equation);
         this.expression = new ExpressionBuilder(this.equation)
                 .variables(this.variables)
                 .build();
@@ -125,4 +117,29 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
     public Set<String> getScopeKeys() {
         return this.variables;
     }
+
+    private static final Set<String> getVariables(final String equation) {
+        final StringBuilder builder = new StringBuilder();
+        final char[] chars = equation.toCharArray();
+        for (int i = 0; i < chars.length; i++) {
+            if ('+' == chars[i] || '-' == chars[i] || '*' == chars[i] ||
+                    '/' == chars[i] || '^' == chars[i] || '%' == chars[i] ||
+                    '(' == chars[i] || ')' == chars[i])
+                builder.append(" ");
+            else
+                builder.append(chars[i]);
+        }
+        final Set<String> variables = new LinkedHashSet<>();
+        for (final String slot : builder.toString().split(" ")) {
+            if (!slot.trim().isEmpty() && !slot.equals("abs") && !slot.equals("acos") &&
+                    !slot.equals("asin") && !slot.equals("atan") && !slot.equals("cbrt") &&
+                    !slot.equals("ceil") && !slot.equals("cos") && !slot.equals("cosh") &&
+                    !slot.equals("exp") && !slot.equals("floor") && !slot.equals("log") &&
+                    !slot.equals("log10") && !slot.equals("log2") && !slot.equals("sin") &&
+                    !slot.equals("sinh") && !slot.equals("sqrt") && !slot.equals("tan") &&
+                    !slot.equals("tanh") && !slot.equals("signum"))
+                variables.add(slot);
+        }
+        return variables;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/624a8d70/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 0af81bd..b93f7ab 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -71,7 +71,7 @@ public class TinkerGraphPlayTest {
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
         GraphTraversalSource g = graph.traversal();
-        System.out.println(g.V().as("a").out("knows").math("((a ^ _) / a)").by("age").by(bothE().count()).toList());
+        System.out.println(g.withSideEffect("x",10.1d).V().as("a").out("knows").math("((a ^ _) / a) + x").by("age").by(bothE().count()).by().toList());
     }
 
     @Test


[06/13] tinkerpop git commit: I changed a method in TraveraslHelper to LinkedHashSet. I no longer needed this method so I reverted it back to what master/ has it as.

Posted by sp...@apache.org.
I changed a method in TraveraslHelper to LinkedHashSet. I no longer needed this method so I reverted it back to what master/ has it as.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e8ca769c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e8ca769c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e8ca769c

Branch: refs/heads/TINKERPOP-1799
Commit: e8ca769cb9f7f06b7b55fd84d4ed8b4f5187aba4
Parents: 7217823
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 11:34:04 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 11:34:04 2017 -0600

----------------------------------------------------------------------
 .../tinkerpop/gremlin/process/traversal/util/TraversalHelper.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e8ca769c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index 9db3ea8..842cea7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -52,7 +52,6 @@ import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Optional;
@@ -560,7 +559,7 @@ public final class TraversalHelper {
     }
 
     public static Set<String> getLabels(final Traversal.Admin<?, ?> traversal) {
-        return TraversalHelper.getLabels(new LinkedHashSet<>(), traversal);
+        return TraversalHelper.getLabels(new HashSet<>(), traversal);
     }
 
     private static Set<String> getLabels(final Set<String> labels, final Traversal.Admin<?, ?> traversal) {


[12/13] tinkerpop git commit: Merge branch 'TINKERPOP-1632'

Posted by sp...@apache.org.
Merge branch 'TINKERPOP-1632'


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/0a183f85
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0a183f85
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0a183f85

Branch: refs/heads/TINKERPOP-1799
Commit: 0a183f853434c8e68b06749ff1bbc10b286ec875
Parents: 4bcf8ae 73b712d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Oct 13 08:48:41 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Oct 13 08:48:41 2017 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   1 +
 docs/src/reference/the-traversal.asciidoc       |  44 +++++
 docs/src/upgrade/release-3.3.x.asciidoc         |  36 ++++
 gremlin-core/pom.xml                            |   5 +
 .../traversal/dsl/graph/GraphTraversal.java     |  14 ++
 .../gremlin/process/traversal/dsl/graph/__.java |   7 +
 .../process/traversal/step/map/MathStep.java    | 171 +++++++++++++++++++
 .../process/traversal/util/TraversalHelper.java |   1 -
 .../traversal/dsl/graph/GraphTraversalTest.java |   2 +
 .../traversal/step/map/MathStepTest.java        |  64 +++++++
 .../Process/Traversal/GraphTraversal.cs         |   9 +
 .../src/Gremlin.Net/Process/Traversal/__.cs     |   8 +
 .../gremlin_python/process/graph_traversal.py   |  12 ++
 .../gremlin/process/ProcessComputerSuite.java   |   4 +
 .../gremlin/process/ProcessStandardSuite.java   |   3 +
 .../process/traversal/step/map/MathTest.java    | 130 ++++++++++++++
 .../structure/TinkerGraphPlayTest.java          |  53 +-----
 17 files changed, 515 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0a183f85/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index d941f62,102586d..f948391
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -25,7 -25,7 +25,8 @@@ image::https://raw.githubusercontent.co
  
  This release also includes changes from <<release-3-2-7, 3.2.7>>.
  
 +* Added support for GraphSON 3.0 in Gremlin.Net.
+ * Added `math()`-step which supports scientific calculator capabilities for numbers within a traversal.
  * Added missing `GraphTraversalSource.addE()`-method to `GremlinDslProcessor`.
  * Changed `to()` and `from()` traversal-based steps to take a wildcard `?` instead of of `E`.
  * Added `addV(traversal)` and `addE(traversal)` so that created element labels can be determined dynamically.


[11/13] tinkerpop git commit: Reusing the Expression on each map() as recommended by @twilmes. Also, added a new test project()-based test case that demonstrates that math() works for map key scopes.

Posted by sp...@apache.org.
Reusing the Expression on each map() as recommended by @twilmes. Also, added a new test project()-based test case that demonstrates that math() works for map key scopes.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/73b712d2
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/73b712d2
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/73b712d2

Branch: refs/heads/TINKERPOP-1799
Commit: 73b712d20b9cd63dd46245a42d88e0e120ed790c
Parents: e966422
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Oct 5 13:06:03 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Oct 5 13:06:03 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MathStep.java      | 15 ++++++++-------
 .../process/traversal/step/map/MathTest.java      | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/73b712d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
index a10ec5e..b34c3ca 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -48,6 +48,7 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
     private static final String CURRENT = "_";
     private final String equation;
     private final Set<String> variables;
+    private final Expression expression;
     private TraversalRing<S, Number> traversalRing = new TraversalRing<>();
     private Set<String> keepLabels;
 
@@ -55,7 +56,10 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
         super(traversal);
         this.equation = equation;
         this.variables = MathStep.getVariables(this.equation);
-
+        this.expression = new ExpressionBuilder(this.equation)
+                .variables(this.variables)
+                .implicitMultiplication(false)
+                .build();
     }
 
     @Override
@@ -65,18 +69,15 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
 
     @Override
     protected Double map(final Traverser.Admin<S> traverser) {
-        final Expression expression = new ExpressionBuilder(this.equation)
-                .variables(this.variables)
-                .implicitMultiplication(false)
-                .build();
+        final Expression localExpression = new Expression(this.expression);
         for (final String var : this.variables) {
-            expression.setVariable(var,
+            localExpression.setVariable(var,
                     var.equals(CURRENT) ?
                             TraversalUtil.applyNullable(traverser, this.traversalRing.next()).doubleValue() :
                             TraversalUtil.applyNullable((S) this.getNullableScopeValue(Pop.last, var, traverser), this.traversalRing.next()).doubleValue());
         }
         this.traversalRing.reset();
-        return expression.evaluate();
+        return localExpression.evaluate();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/73b712d2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
index 9858d28..20d8392 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
@@ -33,7 +33,10 @@ import java.util.function.BiFunction;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
 import static org.apache.tinkerpop.gremlin.process.traversal.Operator.sum;
+import static org.apache.tinkerpop.gremlin.process.traversal.Order.decr;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.math;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.sack;
 import static org.junit.Assert.assertEquals;
 
@@ -51,6 +54,8 @@ public abstract class MathTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Integer, Double> get_g_withSackX1X_injectX1X_repeatXsackXsumX_byXconstantX1XXX_timesX5X_emit_mathXsin__X_byXsackX();
 
+    public abstract Traversal<Vertex, String> get_g_V_projectXa_b_cX_byXbothE_weight_sumX_byXbothE_countX_byXnameX_order_byXmathXa_div_bX_decrX_selectXcX();
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_asXaX_outXknowsX_asXbX_mathXa_plus_bX_byXageX() {
@@ -87,6 +92,14 @@ public abstract class MathTest extends AbstractGremlinProcessTest {
         assertEquals(-0.27941549819892586d, traversal.next(), 0.01d);
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_projectXa_b_cX_byXbothE_weight_sumX_byXbothE_countX_byXnameX_order_byXmathXa_div_bX_decrX_selectXcX() {
+        final Traversal<Vertex, String> traversal = get_g_V_projectXa_b_cX_byXbothE_weight_sumX_byXbothE_countX_byXnameX_order_byXmathXa_div_bX_decrX_selectXcX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList("ripple", "josh", "marko", "vadas", "lop", "peter"), traversal);
+    }
+
     public static class Traversals extends MathTest {
 
         @Override
@@ -108,5 +121,10 @@ public abstract class MathTest extends AbstractGremlinProcessTest {
         public Traversal<Integer, Double> get_g_withSackX1X_injectX1X_repeatXsackXsumX_byXconstantX1XXX_timesX5X_emit_mathXsin__X_byXsackX() {
             return g.withSack(1).inject(1).repeat(__.sack((BiFunction) sum).by(__.constant(1))).times(10).emit().math("sin _").by(sack());
         }
+
+        @Override
+        public Traversal<Vertex, String> get_g_V_projectXa_b_cX_byXbothE_weight_sumX_byXbothE_countX_byXnameX_order_byXmathXa_div_bX_decrX_selectXcX() {
+            return g.V().project("a", "b", "c").by(bothE().values("weight").sum()).by(bothE().count()).by("name").order().by(math("a / b"), decr).select("c");
+        }
     }
 }
\ No newline at end of file


[08/13] tinkerpop git commit: made a more complex variable grabbing test case.

Posted by sp...@apache.org.
made a more complex variable grabbing test case.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2288b962
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2288b962
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2288b962

Branch: refs/heads/TINKERPOP-1799
Commit: 2288b9620f1cc5bbed12515d0e51c2ec20877bda
Parents: 4ff9310
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 13:38:50 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 13:38:50 2017 -0600

----------------------------------------------------------------------
 .../tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2288b962/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
index 181085c..85464e9 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
@@ -54,7 +54,7 @@ public class MathStepTest extends StepTest {
         assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z")));
         assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z + b + a")));
         assertEquals(Arrays.asList("a_ASDF", "b", "_", "x", "z", "a"), new ArrayList<>(MathStep.getVariables("(a_ASDF + b / _) + log2 (x^3)^z + b + a")));
-        assertEquals(Arrays.asList("a_ASDF", "b", "_", "x", "z", "a"), new ArrayList<>(MathStep.getVariables("(a_ASDF + b / _) + log2 (x^3)^z + b + a")));
+        assertEquals(Arrays.asList("a_ASDF", "bzz_", "_", "x", "z", "a_var", "d"), new ArrayList<>(MathStep.getVariables("((a_ASDF + bzz_ / _) + log2 (x^3)^z + bzz_ + (sinh (a_var + 10))) / (2.0265 * d)")));
         assertEquals(Arrays.asList("ac", "b", "_", "x", "z2"), new ArrayList<>(MathStep.getVariables("(ac + b / _) + log2 (x^3)^z2 + b + (tan (log10 ac / sqrt b))")));
     }
 


[05/13] tinkerpop git commit: added math()-step to the reference docs and updated CHANGELOG and upgrade docs.

Posted by sp...@apache.org.
added math()-step to the reference docs and updated CHANGELOG and upgrade docs.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7217823c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7217823c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7217823c

Branch: refs/heads/TINKERPOP-1799
Commit: 7217823c3ea73f2d32ffa975e417dcd49d40cbdd
Parents: dfddcca
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 11:30:55 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 11:30:55 2017 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                        |  1 +
 docs/src/reference/the-traversal.asciidoc | 44 ++++++++++++++++++++++++++
 docs/src/upgrade/release-3.3.x.asciidoc   | 36 +++++++++++++++++++++
 3 files changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7217823c/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index c958d1e..102586d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 This release also includes changes from <<release-3-2-7, 3.2.7>>.
 
+* Added `math()`-step which supports scientific calculator capabilities for numbers within a traversal.
 * Added missing `GraphTraversalSource.addE()`-method to `GremlinDslProcessor`.
 * Changed `to()` and `from()` traversal-based steps to take a wildcard `?` instead of of `E`.
 * Added `addV(traversal)` and `addE(traversal)` so that created element labels can be determined dynamically.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7217823c/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index de99b7f..de64a6c 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -1207,6 +1207,50 @@ system to leverage the filter for index lookups.
 IMPORTANT: A `where()`-step is a filter and thus, variables within a `where()` clause are not globally bound to the
 path of the traverser in `match()`. As such, `where()`-steps in `match()` are used for filtering, not binding.
 
+[[math-step]]
+=== Math Step
+
+The `math()`-step (*math*) enables scientific calculator functionality within Gremlin. This step deviates from the common
+function composition and nesting formalisms to provide an easy to read string-based math processor. Variables within the
+equation map to scopes in Gremlin -- e.g. path labels, side-effects, or incoming map keys. This step supports
+`by()`-modulation where the `by()`-modulators are applied in the order in which the variables are first referenced
+within the equation. Note that the reserved variable `_` refers to the current numeric traverser object incoming to the
+`math()`-step.
+
+[gremlin-groovy,modern]
+----
+g.V().as('a').out('knows').as('b').math('a + b').by('age')
+g.V().as('a').out('created').as('b').
+  math('b + a').
+    by(both().count().math('_ + 100')).
+    by('age')
+g.withSideEffect('x',10).V().values('age').math('_ / x')
+g.withSack(1).V(1).repeat(sack(sum).by(constant(1))).times(10).emit().sack().math('sin _')
+----
+
+The operators supported by the calculator include: `*`, `+`, `\`, `^`, and `%`.
+Furthermore, the following built in functions are provided:
+
+* `abs`: absolute value
+* `acos`: arc cosine
+* `asin`: arc sine
+* `atan`: arc tangent
+* `cbrt`: cubic root
+* `ceil`: nearest upper integer
+* `cos`: cosine
+* `cosh`: hyperbolic cosine
+* `exp`: euler's number raised to the power (`e^x`)
+* `floor`: nearest lower integer
+* `log`: logarithmus naturalis (base e)
+* `log10`: logarithm (base 10)
+* `log2`: logarithm (base 2)
+* `sin`: sine
+* `sinh`: hyperbolic sine
+* `sqrt`: square root
+* `tan`: tangent
+* `tanh`: hyperbolic tangent
+* `signum`: signum function
+
 [[max-step]]
 === Max Step
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7217823c/docs/src/upgrade/release-3.3.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index f18dcd1..e36bdf1 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -29,11 +29,45 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.3.1/CHANGELOG.asc
 
 === Upgrading for Users
 
+==== Added `math()`-step for Scientific Traversal Computing
+
+`GraphTraversal.math(String)` was added. This step provides scientific calculator capabilities to a Gremlin traversal.
+
+[source,groovy]
+----
+gremlin> g.V().as('a').out('knows').as('b').math('a + b').by('age')
+==>56.0
+==>61.0
+gremlin> g.V().as('a').out('created').as('b').
+......1>   math('b + a').
+......2>     by(both().count().math('_ + 100')).
+......3>     by('age')
+==>132.0
+==>133.0
+==>135.0
+==>138.0
+gremlin> g.withSack(1).V(1).repeat(sack(sum).by(constant(1))).times(10).emit().sack().math('sin _')
+==>0.9092974268256817
+==>0.1411200080598672
+==>-0.7568024953079282
+==>-0.9589242746631385
+==>-0.27941549819892586
+==>0.6569865987187891
+==>0.9893582466233818
+==>0.4121184852417566
+==>-0.5440211108893698
+==>-0.9999902065507035
+----
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1632[TINKERPOP-1632]
+
 ==== Changed Typing on `from()` and `to()`
 
 The `from()` and `to()` steps of `GraphTraversal` have a `Traversal<E,Vertex>` overload. The `E` has been changed to `?`
 in order to reduce `< >`-based coersion in strongly type Gremlin language variants.
 
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1793[TINKERPOP-1793]
+
 ==== addV(traversal) and addE(traversal)
 
 The `GraphTraversal` and `GraphTraversalSource` methods of `addV()` and `addE()` have been extended to support dynamic
@@ -58,6 +92,8 @@ gremlin> g.V().has('name','stephen').outE().valueMap(true)
 gremlin>
 ----
 
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1793[TINKERPOP-1793]
+
 ==== PageRankVertexProgram
 
 There were two major bugs in the way in which PageRank was being calculated in `PageRankVertexProgram`. First, teleportation


[07/13] tinkerpop git commit: added a regular expression to identify variables in the equation (and in their proper order). This code was provided by @dkuppitz via chat.

Posted by sp...@apache.org.
added a regular expression to identify variables in the equation (and in their proper order). This code was provided by @dkuppitz via chat.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/4ff9310a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/4ff9310a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/4ff9310a

Branch: refs/heads/TINKERPOP-1799
Commit: 4ff9310aa607e02a3f37345a3bd8f1b3b4b1c89e
Parents: e8ca769
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 13:33:27 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 13:33:27 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MathStep.java    | 54 ++++++++++----------
 .../traversal/step/map/MathStepTest.java        |  3 ++
 2 files changed, 30 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4ff9310a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
index 6dd5338..53abc30 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -21,7 +21,6 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
 
 import net.objecthunter.exp4j.Expression;
 import net.objecthunter.exp4j.ExpressionBuilder;
-import org.apache.commons.lang.StringUtils;
 import org.apache.tinkerpop.gremlin.process.traversal.Pop;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
@@ -38,6 +37,8 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -133,32 +134,6 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
             return this.variables;
     }
 
-    protected static final Set<String> getVariables(final String equation) {
-        final StringBuilder builder = new StringBuilder();
-        final char[] chars = equation.toCharArray();
-        for (int i = 0; i < chars.length; i++) {
-            if ('+' == chars[i] || '-' == chars[i] || '*' == chars[i] ||
-                    '/' == chars[i] || '^' == chars[i] || '%' == chars[i] ||
-                    '(' == chars[i] || ')' == chars[i])
-                builder.append(" ");
-            else
-                builder.append(chars[i]);
-        }
-        final Set<String> variables = new LinkedHashSet<>();
-        for (final String slot : builder.toString().split(" ")) {
-            if (!slot.trim().isEmpty() && !StringUtils.isNumeric(slot) &&
-                    !slot.equals("abs") && !slot.equals("acos") &&
-                    !slot.equals("asin") && !slot.equals("atan") && !slot.equals("cbrt") &&
-                    !slot.equals("ceil") && !slot.equals("cos") && !slot.equals("cosh") &&
-                    !slot.equals("exp") && !slot.equals("floor") && !slot.equals("log") &&
-                    !slot.equals("log10") && !slot.equals("log2") && !slot.equals("sin") &&
-                    !slot.equals("sinh") && !slot.equals("sqrt") && !slot.equals("tan") &&
-                    !slot.equals("tanh") && !slot.equals("signum"))
-                variables.add(slot);
-        }
-        return variables;
-    }
-
     @Override
     public void setKeepLabels(final Set<String> labels) {
         this.keepLabels = labels;
@@ -168,4 +143,29 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
     public Set<String> getKeepLabels() {
         return this.keepLabels;
     }
+
+    ///
+
+    private static final String[] FUNCTIONS = new String[]{
+            "abs", "acos", "asin", "atan",
+            "cbrt", "ceil", "cos", "cosh",
+            "exp",
+            "floor",
+            "log", "log10", "log2",
+            "signum", "sin", "sinh", "sqrt",
+            "tan", "tanh"
+    };
+
+    private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\b(?!" +
+            String.join("|", FUNCTIONS) + "|([0-9]+))([a-zA-Z_][a-zA-Z0-9_]*)\\b");
+
+    protected static final Set<String> getVariables(final String equation) {
+        final Matcher matcher = VARIABLE_PATTERN.matcher(equation);
+        final Set<String> variables = new LinkedHashSet<>();
+        while (matcher.find()) {
+            variables.add(matcher.group());
+        }
+        return variables;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4ff9310a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
index 334a367..181085c 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStepTest.java
@@ -53,6 +53,9 @@ public class MathStepTest extends StepTest {
         assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / sin 2")));
         assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z")));
         assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z + b + a")));
+        assertEquals(Arrays.asList("a_ASDF", "b", "_", "x", "z", "a"), new ArrayList<>(MathStep.getVariables("(a_ASDF + b / _) + log2 (x^3)^z + b + a")));
+        assertEquals(Arrays.asList("a_ASDF", "b", "_", "x", "z", "a"), new ArrayList<>(MathStep.getVariables("(a_ASDF + b / _) + log2 (x^3)^z + b + a")));
+        assertEquals(Arrays.asList("ac", "b", "_", "x", "z2"), new ArrayList<>(MathStep.getVariables("(ac + b / _) + log2 (x^3)^z2 + b + (tan (log10 ac / sqrt b))")));
     }
 
 }
\ No newline at end of file


[03/13] tinkerpop git commit: added MathTest to test math() using step labels, side-effects, and implicit current -- and with various uses of by()-modulation. This is a really cool step.

Posted by sp...@apache.org.
added MathTest to test math() using step labels, side-effects, and implicit current -- and with various uses of by()-modulation. This is a really cool step.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/c36493b6
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/c36493b6
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/c36493b6

Branch: refs/heads/TINKERPOP-1799
Commit: c36493b6d66406b0d6b50e6c292e6d43216b4c4c
Parents: 624a8d7
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 4 10:42:06 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 4 10:42:06 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MathStep.java    |  1 +
 .../gremlin/process/ProcessComputerSuite.java   |  4 +
 .../gremlin/process/ProcessStandardSuite.java   |  3 +
 .../process/traversal/step/map/MathTest.java    | 88 ++++++++++++++++++++
 .../structure/TinkerGraphPlayTest.java          |  2 +-
 5 files changed, 97 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36493b6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
index aec395c..ef88aac 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathStep.java
@@ -53,6 +53,7 @@ public final class MathStep<S> extends MapStep<S, Double> implements ByModulatin
         this.variables = MathStep.getVariables(this.equation);
         this.expression = new ExpressionBuilder(this.equation)
                 .variables(this.variables)
+                .implicitMultiplication(false)
                 .build();
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36493b6/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
index d5ec67a..0e0fc81 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
@@ -57,6 +57,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.LoopsTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MathTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MinTest;
@@ -147,6 +148,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
             MapTest.Traversals.class,
             MatchTest.CountMatchTraversals.class,
             MatchTest.GreedyMatchTraversals.class,
+            MathTest.Traversals.class,
             MaxTest.Traversals.class,
             MeanTest.Traversals.class,
             MinTest.Traversals.class,
@@ -230,6 +232,8 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
             CountTest.class,
             FlatMapTest.class,
             FoldTest.class,
+            MatchTest.class,
+            MathTest.class,
             MapTest.class,
             MaxTest.class,
             MeanTest.class,

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36493b6/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
index b6d1830..18e25d7 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
@@ -54,6 +54,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.LoopsTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MathTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MinTest;
@@ -141,6 +142,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
             MapTest.Traversals.class,
             MatchTest.CountMatchTraversals.class,
             MatchTest.GreedyMatchTraversals.class,
+            MathTest.Traversals.class,
             MaxTest.Traversals.class,
             MeanTest.Traversals.class,
             MinTest.Traversals.class,
@@ -223,6 +225,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
             LoopsTest.class,
             MapTest.class,
             MatchTest.class,
+            MathTest.class,
             MaxTest.class,
             MeanTest.class,
             MinTest.class,

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36493b6/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
new file mode 100644
index 0000000..94065e9
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MathTest.java
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Arrays;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(GremlinProcessRunner.class)
+public abstract class MathTest extends AbstractGremlinProcessTest {
+
+    public abstract Traversal<Vertex, Double> get_g_V_asXaX_outXknowsX_asXbX_mathXa_plus_bX_byXageX();
+
+    public abstract Traversal<Vertex, Double> get_g_withSideEffectXx_100X_V_age_mathX__plus_xX();
+
+    public abstract Traversal<Vertex, Double> get_g_V_asXaX_outXcreatedX_asXbX_mathXb_plus_aX_byXinXcreatedX_countX_byXageX();
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_asXaX_outXknowsX_asXbX_mathXa_plus_bX_byXageX() {
+        final Traversal<Vertex, Double> traversal = get_g_V_asXaX_outXknowsX_asXbX_mathXa_plus_bX_byXageX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList(56.0d, 61.0d), traversal);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_withSideEffectXx_100X_V_age_mathX__plus_xX() {
+        final Traversal<Vertex, Double> traversal = get_g_withSideEffectXx_100X_V_age_mathX__plus_xX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList(129.0d, 127.0d, 132.0d, 135.0d), traversal);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_asXaX_outXcreatedX_asXbX_mathXb_plus_aX_byXinXcreatedX_countX_byXageX() {
+        final Traversal<Vertex, Double> traversal = get_g_V_asXaX_outXcreatedX_asXbX_mathXb_plus_aX_byXinXcreatedX_countX_byXageX();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList(32.0d, 33.0d, 35.0d, 38.0d), traversal);
+    }
+
+    public static class Traversals extends MathTest {
+
+        @Override
+        public Traversal<Vertex, Double> get_g_V_asXaX_outXknowsX_asXbX_mathXa_plus_bX_byXageX() {
+            return g.V().as("a").out("knows").as("b").math("a + b").by("age");
+        }
+
+        @Override
+        public Traversal<Vertex, Double> get_g_withSideEffectXx_100X_V_age_mathX__plus_xX() {
+            return g.withSideEffect("x", 100).V().values("age").math("_ + x");
+        }
+
+        @Override
+        public Traversal<Vertex, Double> get_g_V_asXaX_outXcreatedX_asXbX_mathXb_plus_aX_byXinXcreatedX_countX_byXageX() {
+            return g.V().as("a").out("created").as("b").math("b + a").by(in("created").count()).by("age");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36493b6/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index b93f7ab..736b146 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -71,7 +71,7 @@ public class TinkerGraphPlayTest {
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
         GraphTraversalSource g = graph.traversal();
-        System.out.println(g.withSideEffect("x",10.1d).V().as("a").out("knows").math("((a ^ _) / a) + x").by("age").by(bothE().count()).by().toList());
+        System.out.println(g.V().values("age").toList());
     }
 
     @Test