You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2017/05/15 15:31:36 UTC

[1/3] tinkerpop git commit: using [...] syntax for Map construction in GroovyTranslator instead of new LinkedHashMap().

Repository: tinkerpop
Updated Branches:
  refs/heads/master 431c1d6a5 -> 1300e4b53


using [...] syntax for Map construction in GroovyTranslator instead of new LinkedHashMap().


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

Branch: refs/heads/master
Commit: e4f6842bc6097750eded8d59095605ba4c81c6ae
Parents: 37e1716
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu May 11 15:56:26 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu May 11 15:56:26 2017 -0600

----------------------------------------------------------------------
 .../gremlin/groovy/jsr223/GroovyTranslatorTest.java  | 15 +++++++++++++--
 .../gremlin/groovy/jsr223/GroovyTranslator.java      | 11 ++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e4f6842b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index 59903ac..133646a 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@ -27,7 +27,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
@@ -38,8 +37,9 @@ import org.junit.Test;
 import javax.script.Bindings;
 import javax.script.SimpleBindings;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -117,6 +117,17 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
     }
 
     @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldHandleMaps() {
+        GraphTraversalSource g = graph.traversal();
+        String script = GroovyTranslator.of("g").translate(g.V().id().is(new LinkedHashMap() {{
+            put(3, "32");
+            put(Arrays.asList(1, 2, 3.1d), 4);
+        }}).asAdmin().getBytecode());
+        assertEquals(script, "g.V().id().is([((int) 3):(\"32\"),([(int) 1, (int) 2, 3.1d]):((int) 4)])");
+    }
+
+    @Test
     public void shouldHaveValidToString() {
         assertEquals("translator[h:gremlin-groovy]", GroovyTranslator.of("h").toString());
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e4f6842b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
index d102037..c3017db 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
@@ -127,15 +127,16 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
             }
             return list.toString();
         } else if (object instanceof Map) {
-            final StringBuilder map = new StringBuilder("new LinkedHashMap(){{");
+            final StringBuilder map = new StringBuilder("[");
             for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
-                map.append("put(").
+                map.append("(").
                         append(convertToString(entry.getKey())).
-                        append(",").
+                        append("):(").
                         append(convertToString(entry.getValue())).
-                        append(");");
+                        append("),");
             }
-            return map.append("}}").toString();
+            map.deleteCharAt(map.length()-1);
+            return map.append("]").toString();
         } else if (object instanceof Long)
             return object + "L";
         else if (object instanceof Double)


[3/3] tinkerpop git commit: merged tp32 GroovyTranslator update.

Posted by ok...@apache.org.
merged tp32 GroovyTranslator update.


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

Branch: refs/heads/master
Commit: 1300e4b533700056024da2394385218d71f6cf13
Parents: 431c1d6 b755788
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon May 15 09:30:55 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon May 15 09:30:55 2017 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                   |  1 +
 .../gremlin/groovy/jsr223/GroovyTranslator.java      | 11 ++++++-----
 .../gremlin/groovy/jsr223/GroovyTranslatorTest.java  | 15 +++++++++++++--
 3 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1300e4b5/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1300e4b5/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1300e4b5/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --cc gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index 654cb00,0000000..a7074b0
mode 100644,000000..100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@@ -1,123 -1,0 +1,134 @@@
 +/*
 + *  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.groovy.jsr223;
 +
 +import org.apache.commons.configuration.MapConfiguration;
- import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
- import org.apache.tinkerpop.gremlin.LoadGraphWith;
 +import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 +import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
 +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
 +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
 +import org.apache.tinkerpop.gremlin.structure.Vertex;
 +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
 +import org.apache.tinkerpop.gremlin.util.function.Lambda;
 +import org.junit.Test;
 +
 +import javax.script.Bindings;
 +import javax.script.SimpleBindings;
 +import java.util.ArrayList;
++import java.util.Arrays;
 +import java.util.HashMap;
++import java.util.LinkedHashMap;
 +import java.util.List;
 +
 +import static org.junit.Assert.assertEquals;
 +import static org.junit.Assert.assertFalse;
 +
 +/**
 + * @author Marko A. Rodriguez (http://markorodriguez.com)
 + */
 +public class GroovyTranslatorTest {
 +
 +    @Test
 +    public void shouldHandleStrategies() throws Exception {
 +        final TinkerGraph graph = TinkerFactory.createModern();
 +        GraphTraversalSource g = graph.traversal();
 +        g = g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
 +            put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
 +        }})));
 +        final Bindings bindings = new SimpleBindings();
 +        bindings.put("g", g);
 +        Traversal.Admin<Vertex, Object> traversal = new GremlinGroovyScriptEngine().eval(g.V().values("name").asAdmin().getBytecode(), bindings);
 +        assertEquals("marko", traversal.next());
 +        assertFalse(traversal.hasNext());
 +        //
 +        traversal = new GremlinGroovyScriptEngine().eval(g.withoutStrategies(SubgraphStrategy.class).V().count().asAdmin().getBytecode(), bindings);
 +        assertEquals(new Long(6), traversal.next());
 +        assertFalse(traversal.hasNext());
 +        //
 +        traversal = new GremlinGroovyScriptEngine().eval(g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
 +            put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
 +        }})), ReadOnlyStrategy.instance()).V().values("name").asAdmin().getBytecode(), bindings);
 +        assertEquals("marko", traversal.next());
 +        assertFalse(traversal.hasNext());
 +    }
 +
 +    @Test
 +    public void shouldSupportStringSupplierLambdas() throws Exception {
 +        final TinkerGraph graph = TinkerFactory.createModern();
 +        GraphTraversalSource g = graph.traversal();
 +        g = g.withStrategies(new TranslationStrategy(g, GroovyTranslator.of("g")));
 +        GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1)
 +                .V()
 +                .filter(Lambda.predicate("it.get().label().equals('person')"))
 +                .flatMap(Lambda.function("it.get().vertices(Direction.OUT)"))
 +                .map(Lambda.<Traverser<Object>, Integer>function("it.get().value('name').length()"))
 +                .sideEffect(Lambda.consumer("{ x -> x.sideEffects(\"lengthSum\", x.<Integer>sideEffects('lengthSum') + x.get()) }"))
 +                .order().by(Lambda.comparator("a,b -> a <=> b"))
 +                .sack(Lambda.biFunction("{ a,b -> a + b }"))
 +                .asAdmin();
 +        final List<Integer> sacks = new ArrayList<>();
 +        final List<Integer> lengths = new ArrayList<>();
 +        while (t.hasNext()) {
 +            final Traverser.Admin<Integer> traverser = t.nextTraverser();
 +            sacks.add(traverser.sack());
 +            lengths.add(traverser.get());
 +        }
 +        assertFalse(t.hasNext());
 +        //
 +        assertEquals(6, lengths.size());
 +        assertEquals(3, lengths.get(0).intValue());
 +        assertEquals(3, lengths.get(1).intValue());
 +        assertEquals(3, lengths.get(2).intValue());
 +        assertEquals(4, lengths.get(3).intValue());
 +        assertEquals(5, lengths.get(4).intValue());
 +        assertEquals(6, lengths.get(5).intValue());
 +        ///
 +        assertEquals(6, sacks.size());
 +        assertEquals(4, sacks.get(0).intValue());
 +        assertEquals(4, sacks.get(1).intValue());
 +        assertEquals(4, sacks.get(2).intValue());
 +        assertEquals(5, sacks.get(3).intValue());
 +        assertEquals(6, sacks.get(4).intValue());
 +        assertEquals(7, sacks.get(5).intValue());
 +        //
 +        assertEquals(24, t.getSideEffects().<Number>get("lengthSum").intValue());
 +    }
 +
 +    @Test
++    public void shouldHandleMaps() {
++        final TinkerGraph graph = TinkerFactory.createModern();
++        GraphTraversalSource g = graph.traversal();
++        String script = GroovyTranslator.of("g").translate(g.V().id().is(new LinkedHashMap() {{
++            put(3, "32");
++            put(Arrays.asList(1, 2, 3.1d), 4);
++        }}).asAdmin().getBytecode());
++        assertEquals(script, "g.V().id().is([((int) 3):(\"32\"),([(int) 1, (int) 2, 3.1d]):((int) 4)])");
++    }
++
++    @Test
 +    public void shouldHaveValidToString() {
 +        assertEquals("translator[h:gremlin-groovy]", GroovyTranslator.of("h").toString());
 +    }
 +}


[2/3] tinkerpop git commit: updated CHANGELOG.

Posted by ok...@apache.org.
updated CHANGELOG.


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

Branch: refs/heads/master
Commit: b755788c6fe7b902a3e81f3c2f11eb5a8b02c4be
Parents: e4f6842
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu May 11 16:00:24 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu May 11 16:00:24 2017 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b755788c/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6fb3372..7057aac 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Now using Groovy `[...]` map notation in `GroovyTranslator` instead of `new LinkedHashMap(){{ }}`.
 * Maintained type information on `Traversal.promise()`.
 * Propagated exception to `Future` instead of calling thread in `RemoteConnection`.
 * Fixed a bug in `RepeatUnrollStrategy` where `LoopsStep` and `LambdaHolder` should invalidate the strategy's application.