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.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 14a254320 -> e96642290 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-1632 Commit: e9664229038e87d9974971fb0249ad0f884a22ff Parents: 14a2543 Author: Marko A. RodriguezAuthored: Wed Oct 4 16:58:09 2017 -0600 Committer: Marko A. Rodriguez 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 extends MapStep implements ByModulatin private static final String CURRENT = "_"; private final String equation; private final Set variables; -private TraversalRing
tinkerpop git commit: added a test case for 6.67e−11 notation. passed.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 2288b9620 -> 14a254320 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-1632 Commit: 14a254320bbe242cc83015369cbd24cd3aa14165 Parents: 2288b96 Author: Marko A. RodriguezAuthored: Wed Oct 4 13:41:51 2017 -0600 Committer: Marko A. Rodriguez 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")));
tinkerpop git commit: made a more complex variable grabbing test case.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 4ff9310aa -> 2288b9620 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-1632 Commit: 2288b9620f1cc5bbed12515d0e51c2ec20877bda Parents: 4ff9310 Author: Marko A. RodriguezAuthored: Wed Oct 4 13:38:50 2017 -0600 Committer: Marko A. Rodriguez 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))"))); }
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.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 e8ca769cb -> 4ff9310aa 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-1632 Commit: 4ff9310aa607e02a3f37345a3bd8f1b3b4b1c89e Parents: e8ca769 Author: Marko A. RodriguezAuthored: Wed Oct 4 13:33:27 2017 -0600 Committer: Marko A. Rodriguez 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 extends MapStep implements ByModulatin return this.variables; } -protected static final Set 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 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 labels) { this.keepLabels = labels; @@ -168,4 +143,29 @@ public final class MathStep extends MapStepimplements ByModulatin public Set 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 getVariables(final String equation) { +final Matcher matcher = VARIABLE_PATTERN.matcher(equation); +final Set variables =
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.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 7217823c3 -> e8ca769cb 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-1632 Commit: e8ca769cb9f7f06b7b55fd84d4ed8b4f5187aba4 Parents: 7217823 Author: Marko A. RodriguezAuthored: Wed Oct 4 11:34:04 2017 -0600 Committer: Marko A. Rodriguez 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 getLabels(final Traversal.Admin traversal) { -return TraversalHelper.getLabels(new LinkedHashSet<>(), traversal); +return TraversalHelper.getLabels(new HashSet<>(), traversal); } private static Set getLabels(final Set labels, final Traversal.Admin traversal) {
tinkerpop git commit: added math()-step to the reference docs and updated CHANGELOG and upgrade docs.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 dfddccaaa -> 7217823c3 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-1632 Commit: 7217823c3ea73f2d32ffa975e417dcd49d40cbdd Parents: dfddcca Author: Marko A. RodriguezAuthored: Wed Oct 4 11:30:55 2017 -0600 Committer: Marko A. Rodriguez 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 < >. +* 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)`
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 OL
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 c36493b6d -> dfddccaaa 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-1632 Commit: dfddccaaa85898e046e6b7a5bd81da3d94777d7d Parents: c36493b Author: Marko A. RodriguezAuthored: Wed Oct 4 11:01:53 2017 -0600 Committer: Marko A. Rodriguez 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 extends MapStep implements ByModulating, TraversalParent, Scoping { +public final class MathStep extends MapStepimplements ByModulating, TraversalParent, Scoping, PathProcessor { private static final String CURRENT = "_"; private final String equation; private final Set variables; -private final Expression expression; private TraversalRing
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.
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 624a8d706 -> c36493b6d 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-1632 Commit: c36493b6d66406b0d6b50e6c292e6d43216b4c4c Parents: 624a8d7 Author: Marko A. RodriguezAuthored: Wed Oct 4 10:42:06 2017 -0600 Committer: Marko A. Rodriguez 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 extends MapStep 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
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,
Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1632 6f1a1f702 -> 624a8d706 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-1632 Commit: 624a8d706e150cc15dc2412d66d3ac9a61b90682 Parents: 6f1a1f7 Author: Marko A. RodriguezAuthored: Wed Oct 4 10:27:48 2017 -0600 Committer: Marko A. Rodriguez 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 extends MapStep implements ByModulatin public MathStep(final Traversal.Admin traversal, final String equation) { super(traversal); this.equation = equation; -final Set 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 extends MapStepimplements ByModulatin public Set getScopeKeys() { return this.variables; } + +private static final Set 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 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); +} +
[1/3] tinkerpop git commit: fixed a bug in LambdaRestrictionStrategy where named @ steps were considered lambda. Came up with a different way to check lambdas in .toString(). Works for Groovy, Java, a
Repository: tinkerpop Updated Branches: refs/heads/master e21540169 -> 9aaf49e3e fixed a bug in LambdaRestrictionStrategy where named @ steps were considered lambda. Came up with a different way to check lambdas in .toString(). Works for Groovy, Java, and Python. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/beae74c4 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/beae74c4 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/beae74c4 Branch: refs/heads/master Commit: beae74c43505d1f7732f92a500dc58fc4b142af1 Parents: 1cd042b Author: Marko A. RodriguezAuthored: Mon Oct 2 15:23:33 2017 -0600 Committer: Marko A. Rodriguez Committed: Mon Oct 2 15:23:33 2017 -0600 -- CHANGELOG.asciidoc| 1 + .../verification/LambdaRestrictionStrategy.java | 14 +++--- .../verification/LambdaRestrictionStrategyTest.java | 6 ++ 3 files changed, 14 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/beae74c4/CHANGELOG.asciidoc -- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index e48dfb5..f1ad017 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima [[release-3-2-7]] === TinkerPop 3.2.7 (Release Date: NOT OFFICIALLY RELEASED YET) +* Fixed a bug in `LambdaRestrictionStrategy` where named steps with `@` were being considered lambdas. * `ReferenceVertex` was missing its `label()` string. `ReferenceElement` now supports all label handling. * Added `GraphHelper.cloneElements(Graph original, Graph clone)` to the `gremlin-test` module to quickly clone a graph. * Bump to GMavenPlus 1.6. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/beae74c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java -- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java index 33b29ff..134a852 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java @@ -61,19 +61,19 @@ public final class LambdaRestrictionStrategy extends AbstractTraversalStrategy, Comparator> comparator : ((ComparatorHolder
[3/3] tinkerpop git commit: Merge branch 'tp32'
Merge branch 'tp32' Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9aaf49e3 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9aaf49e3 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9aaf49e3 Branch: refs/heads/master Commit: 9aaf49e3eeefd1d3373765f6f0e6fe0005ea6b97 Parents: e215401 a278edd Author: Marko A. RodriguezAuthored: Wed Oct 4 07:58:59 2017 -0600 Committer: Marko A. Rodriguez Committed: Wed Oct 4 07:58:59 2017 -0600 -- CHANGELOG.asciidoc| 1 + .../verification/LambdaRestrictionStrategy.java | 14 +++--- .../verification/LambdaRestrictionStrategyTest.java | 6 ++ 3 files changed, 14 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9aaf49e3/CHANGELOG.asciidoc --
[1/2] tinkerpop git commit: fixed a bug in LambdaRestrictionStrategy where named @ steps were considered lambda. Came up with a different way to check lambdas in .toString(). Works for Groovy, Java, a
Repository: tinkerpop Updated Branches: refs/heads/tp32 b3e301e66 -> a278edd85 fixed a bug in LambdaRestrictionStrategy where named @ steps were considered lambda. Came up with a different way to check lambdas in .toString(). Works for Groovy, Java, and Python. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/beae74c4 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/beae74c4 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/beae74c4 Branch: refs/heads/tp32 Commit: beae74c43505d1f7732f92a500dc58fc4b142af1 Parents: 1cd042b Author: Marko A. RodriguezAuthored: Mon Oct 2 15:23:33 2017 -0600 Committer: Marko A. Rodriguez Committed: Mon Oct 2 15:23:33 2017 -0600 -- CHANGELOG.asciidoc| 1 + .../verification/LambdaRestrictionStrategy.java | 14 +++--- .../verification/LambdaRestrictionStrategyTest.java | 6 ++ 3 files changed, 14 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/beae74c4/CHANGELOG.asciidoc -- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index e48dfb5..f1ad017 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima [[release-3-2-7]] === TinkerPop 3.2.7 (Release Date: NOT OFFICIALLY RELEASED YET) +* Fixed a bug in `LambdaRestrictionStrategy` where named steps with `@` were being considered lambdas. * `ReferenceVertex` was missing its `label()` string. `ReferenceElement` now supports all label handling. * Added `GraphHelper.cloneElements(Graph original, Graph clone)` to the `gremlin-test` module to quickly clone a graph. * Bump to GMavenPlus 1.6. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/beae74c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java -- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java index 33b29ff..134a852 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/LambdaRestrictionStrategy.java @@ -61,19 +61,19 @@ public final class LambdaRestrictionStrategy extends AbstractTraversalStrategy, Comparator> comparator : ((ComparatorHolder
[2/2] tinkerpop git commit: Merge branch 'tp32'
Merge branch 'tp32' Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e2154016 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e2154016 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e2154016 Branch: refs/heads/master Commit: e215401693d21ed34bb823e1aee49fb1f3821f70 Parents: 26d8dd2 b3e301e Author: Stephen MalletteAuthored: Wed Oct 4 08:28:14 2017 -0400 Committer: Stephen Mallette Committed: Wed Oct 4 08:28:14 2017 -0400 -- CHANGELOG.asciidoc| 1 + .../gremlin/server/op/AbstractEvalOpProcessor.java| 14 +- 2 files changed, 14 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2154016/CHANGELOG.asciidoc -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2154016/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java --
tinkerpop git commit: Truncate error message for "method code too large" exceptions CTR
Repository: tinkerpop Updated Branches: refs/heads/tp32 9f501cdbe -> b3e301e66 Truncate error message for "method code too large" exceptions CTR Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b3e301e6 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b3e301e6 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b3e301e6 Branch: refs/heads/tp32 Commit: b3e301e66ae7410aac6e7c35186ab8d909166ca0 Parents: 9f501cd Author: Stephen MalletteAuthored: Wed Oct 4 08:27:31 2017 -0400 Committer: Stephen Mallette Committed: Wed Oct 4 08:27:31 2017 -0400 -- CHANGELOG.asciidoc| 1 + .../gremlin/server/op/AbstractEvalOpProcessor.java| 14 +- 2 files changed, 14 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3e301e6/CHANGELOG.asciidoc -- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 9f98c08..5ea3034 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima [[release-3-2-7]] === TinkerPop 3.2.7 (Release Date: NOT OFFICIALLY RELEASED YET) +* Truncate the script in error logs and error return messages for "Method code too large" errors in Gremlin Server. * `ReferenceVertex` was missing its `label()` string. `ReferenceElement` now supports all label handling. * Fixed a bug where bytecode containing lambdas would randomly select a traversal source from bindings. * Deprecated `GremlinScriptEngine.eval()` methods and replaced them with new overloads that include the specific `TraversalSource` to bind to. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3e301e6/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java -- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java index 46b3c8d..5c43b4d 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java @@ -312,7 +312,7 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { // up being favorable for this problem if (t instanceof MultipleCompilationErrorsException && t.getMessage().contains("Method code too large!") && ((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) { -final String errorMessage = String.format("The Gremlin statement that was submitted exceed the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", msg); +final String errorMessage = String.format("The Gremlin statement that was submitted exceed the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", trimMessage(msg)); logger.warn(errorMessage); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(errorMessage) @@ -330,6 +330,18 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { }); } +/** + * Used to decrease the size of a Gremlin script that triggered a "method code too large" exception so that it + * doesn't log a massive text string nor return a large error message. + */ +private RequestMessage trimMessage(final RequestMessage msg) { +final RequestMessage trimmedMsg = RequestMessage.from(msg).create(); +if (trimmedMsg.getArgs().containsKey(Tokens.ARGS_GREMLIN)) +trimmedMsg.getArgs().put(Tokens.ARGS_GREMLIN, trimmedMsg.getArgs().get(Tokens.ARGS_GREMLIN).toString().substring(0, 1021) + "..."); + +return trimmedMsg; +} + @FunctionalInterface public interface BindingSupplier { public Bindings get() throws OpProcessorException;
[1/2] tinkerpop git commit: Truncate error message for "method code too large" exceptions CTR
Repository: tinkerpop Updated Branches: refs/heads/master 26d8dd211 -> e21540169 Truncate error message for "method code too large" exceptions CTR Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b3e301e6 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b3e301e6 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b3e301e6 Branch: refs/heads/master Commit: b3e301e66ae7410aac6e7c35186ab8d909166ca0 Parents: 9f501cd Author: Stephen MalletteAuthored: Wed Oct 4 08:27:31 2017 -0400 Committer: Stephen Mallette Committed: Wed Oct 4 08:27:31 2017 -0400 -- CHANGELOG.asciidoc| 1 + .../gremlin/server/op/AbstractEvalOpProcessor.java| 14 +- 2 files changed, 14 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3e301e6/CHANGELOG.asciidoc -- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 9f98c08..5ea3034 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima [[release-3-2-7]] === TinkerPop 3.2.7 (Release Date: NOT OFFICIALLY RELEASED YET) +* Truncate the script in error logs and error return messages for "Method code too large" errors in Gremlin Server. * `ReferenceVertex` was missing its `label()` string. `ReferenceElement` now supports all label handling. * Fixed a bug where bytecode containing lambdas would randomly select a traversal source from bindings. * Deprecated `GremlinScriptEngine.eval()` methods and replaced them with new overloads that include the specific `TraversalSource` to bind to. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3e301e6/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java -- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java index 46b3c8d..5c43b4d 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java @@ -312,7 +312,7 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { // up being favorable for this problem if (t instanceof MultipleCompilationErrorsException && t.getMessage().contains("Method code too large!") && ((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) { -final String errorMessage = String.format("The Gremlin statement that was submitted exceed the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", msg); +final String errorMessage = String.format("The Gremlin statement that was submitted exceed the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", trimMessage(msg)); logger.warn(errorMessage); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(errorMessage) @@ -330,6 +330,18 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { }); } +/** + * Used to decrease the size of a Gremlin script that triggered a "method code too large" exception so that it + * doesn't log a massive text string nor return a large error message. + */ +private RequestMessage trimMessage(final RequestMessage msg) { +final RequestMessage trimmedMsg = RequestMessage.from(msg).create(); +if (trimmedMsg.getArgs().containsKey(Tokens.ARGS_GREMLIN)) +trimmedMsg.getArgs().put(Tokens.ARGS_GREMLIN, trimmedMsg.getArgs().get(Tokens.ARGS_GREMLIN).toString().substring(0, 1021) + "..."); + +return trimmedMsg; +} + @FunctionalInterface public interface BindingSupplier { public Bindings get() throws OpProcessorException;