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 2016/11/04 13:06:24 UTC

[1/6] tinkerpop git commit: added TinkerCountGlobalStep and TinkerGraphCountStrategy which will turn g.V().count() and g.E().count() into direct calls to the .size() of the underlying TinkerGraph.vertices/edges Maps. Removed the OptIn strategy suites in

Repository: tinkerpop
Updated Branches:
  refs/heads/master 154474464 -> f8220be5a


added TinkerCountGlobalStep and TinkerGraphCountStrategy which will turn g.V().count() and g.E().count() into direct calls to the .size() of the underlying TinkerGraph.vertices/edges Maps. Removed the OptIn strategy suites in both TinkerGraph and Neo4jGraph -- this should have been done when these suites were removed long ago.


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

Branch: refs/heads/master
Commit: 0ea3b5e26e76919d080fe224b1b727a132c4b829
Parents: ab48b3f
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Nov 1 15:24:18 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Nov 1 15:24:18 2016 -0600

----------------------------------------------------------------------
 .../gremlin/neo4j/structure/Neo4jGraph.java     |  1 -
 .../step/map/TinkerCountGlobalStep.java         | 75 +++++++++++++++++
 .../optimization/TinkerGraphCountStrategy.java  | 66 +++++++++++++++
 .../tinkergraph/structure/TinkerGraph.java      | 14 ++--
 .../tinkergraph/structure/TinkerHelper.java     |  8 ++
 .../TinkerGraphCountStrategyTest.java           | 88 ++++++++++++++++++++
 6 files changed, 245 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ea3b5e2/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
index d5460c7..5226149 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
@@ -71,7 +71,6 @@ import java.util.stream.Stream;
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
 @Graph.OptIn("org.apache.tinkerpop.gremlin.neo4j.NativeNeo4jSuite")
-@Graph.OptIn("org.apache.tinkerpop.gremlin.neo4j.process.traversal.strategy.Neo4jStrategySuite")
 public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
 
     public static final Logger LOGGER = LoggerFactory.getLogger(Neo4jGraph.class);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ea3b5e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/step/map/TinkerCountGlobalStep.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/step/map/TinkerCountGlobalStep.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/step/map/TinkerCountGlobalStep.java
new file mode 100644
index 0000000..e0e7b80
--- /dev/null
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/step/map/TinkerCountGlobalStep.java
@@ -0,0 +1,75 @@
+/*
+ *  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.tinkergraph.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep;
+import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerHelper;
+
+import java.util.NoSuchElementException;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class TinkerCountGlobalStep<S extends Element> extends AbstractStep<S, Long> {
+
+    private final Class<S> elementClass;
+    private boolean done = false;
+
+    public TinkerCountGlobalStep(final Traversal.Admin traversal, final Class<S> elementClass) {
+        super(traversal);
+        this.elementClass = elementClass;
+    }
+
+    @Override
+    protected Traverser.Admin<Long> processNextStart() throws NoSuchElementException {
+        if (!this.done) {
+            this.done = true;
+            final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get();
+            return this.getTraversal().getTraverserGenerator().generate(Vertex.class.isAssignableFrom(this.elementClass) ?
+                            (long) TinkerHelper.getVertices(graph).size() :
+                            (long) TinkerHelper.getEdges(graph).size(),
+                    (Step) this, 1L);
+        } else
+            throw FastNoSuchElementException.instance();
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.stepString(this, this.elementClass.getSimpleName().toLowerCase());
+    }
+
+    @Override
+    public int hashCode() {
+        return super.hashCode() ^ this.elementClass.hashCode();
+    }
+
+    @Override
+    public void reset() {
+        this.done = false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ea3b5e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
new file mode 100644
index 0000000..d713e21
--- /dev/null
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
@@ -0,0 +1,66 @@
+/*
+ *  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.tinkergraph.process.traversal.strategy.optimization;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountGlobalStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.step.map.TinkerCountGlobalStep;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class TinkerGraphCountStrategy extends AbstractTraversalStrategy<TraversalStrategy.ProviderOptimizationStrategy> implements TraversalStrategy.ProviderOptimizationStrategy {
+
+    private static final TinkerGraphCountStrategy INSTANCE = new TinkerGraphCountStrategy();
+
+    private TinkerGraphCountStrategy() {
+    }
+
+    @Override
+    public void apply(final Traversal.Admin<?, ?> traversal) {
+        if (traversal.getParent() instanceof EmptyStep &&
+                !TraversalHelper.onGraphComputer(traversal) &&
+                2 == traversal.getSteps().size() &&
+                traversal.getStartStep() instanceof GraphStep &&
+                traversal.getEndStep() instanceof CountGlobalStep) {
+            final Class<? extends Element> elementClass = ((GraphStep) traversal.getStartStep()).getReturnClass();
+            TraversalHelper.removeAllSteps(traversal);
+            traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass));
+        }
+    }
+
+    @Override
+    public Set<Class<? extends ProviderOptimizationStrategy>> applyPost() {
+        return Collections.singleton(TinkerGraphStepStrategy.class);
+    }
+
+    public static TinkerGraphCountStrategy instance() {
+        return INSTANCE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ea3b5e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index dba3467..e498b30 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -35,6 +35,7 @@ import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputerView;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.optimization.TinkerGraphCountStrategy;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.optimization.TinkerGraphStepStrategy;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
@@ -69,11 +70,12 @@ import java.util.stream.Stream;
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
-@Graph.OptIn("org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.TinkerGraphStrategySuite")
 public final class TinkerGraph implements Graph {
 
     static {
-        TraversalStrategies.GlobalCache.registerStrategies(TinkerGraph.class, TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone().addStrategies(TinkerGraphStepStrategy.instance()));
+        TraversalStrategies.GlobalCache.registerStrategies(TinkerGraph.class, TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone().addStrategies(
+                TinkerGraphStepStrategy.instance(),
+                TinkerGraphCountStrategy.instance()));
     }
 
     private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration() {{
@@ -120,7 +122,7 @@ public final class TinkerGraph implements Graph {
 
     private final TinkerGraphFeatures features = new TinkerGraphFeatures();
 
-    protected AtomicLong currentId = new AtomicLong(-1l);
+    protected AtomicLong currentId = new AtomicLong(-1L);
     protected Map<Object, Vertex> vertices = new ConcurrentHashMap<>();
     protected Map<Object, Edge> edges = new ConcurrentHashMap<>();
 
@@ -243,7 +245,7 @@ public final class TinkerGraph implements Graph {
         this.vertices.clear();
         this.edges.clear();
         this.variables = null;
-        this.currentId.set(-1l);
+        this.currentId.set(-1L);
         this.vertexIndex = null;
         this.edgeIndex = null;
         this.graphComputerView = null;
@@ -336,8 +338,8 @@ public final class TinkerGraph implements Graph {
             // stuff - doesn't seem likely someone would detach a Titan vertex then try to expect that
             // vertex to be findable in OrientDB
             return clazz.isAssignableFrom(ids[0].getClass()) ?
-               IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(clazz.cast(id).id())).iterator(), Objects::nonNull)
-                : IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(idManager.convert(id))).iterator(), Objects::nonNull);
+                    IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(clazz.cast(id).id())).iterator(), Objects::nonNull)
+                    : IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(idManager.convert(id))).iterator(), Objects::nonNull);
         }
         return TinkerHelper.inComputerMode(this) ?
                 (Iterator<T>) (clazz.equals(Vertex.class) ?

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ea3b5e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
index 53c9bfc..4ed3fdd 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
@@ -203,4 +203,12 @@ public final class TinkerHelper {
         }
         return (Iterator) vertices.iterator();
     }
+
+    public static Map<Object, Vertex> getVertices(final TinkerGraph graph) {
+        return graph.vertices;
+    }
+
+    public static Map<Object, Edge> getEdges(final TinkerGraph graph) {
+        return graph.edges;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ea3b5e2/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
new file mode 100644
index 0000000..296133a
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.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.tinkergraph.process.traversal.strategy.optimization;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversal;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.step.map.TinkerCountGlobalStep;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(Parameterized.class)
+public class TinkerGraphCountStrategyTest {
+
+    @Parameterized.Parameter(value = 0)
+    public Traversal original;
+
+    @Parameterized.Parameter(value = 1)
+    public Traversal optimized;
+
+    @Parameterized.Parameter(value = 2)
+    public Collection<TraversalStrategy> otherStrategies;
+
+    @Test
+    public void doTest() {
+        final TraversalStrategies strategies = new DefaultTraversalStrategies();
+        strategies.addStrategies(TinkerGraphCountStrategy.instance());
+        for (final TraversalStrategy strategy : this.otherStrategies) {
+            strategies.addStrategies(strategy);
+        }
+        this.original.asAdmin().setStrategies(strategies);
+        this.original.asAdmin().applyStrategies();
+        assertEquals(this.optimized, this.original);
+    }
+
+    private static Traversal.Admin<?, ?> countStep(final Class<? extends Element> elementClass) {
+        return new DefaultGraphTraversal<>().addStep(new TinkerCountGlobalStep(EmptyTraversal.instance(), elementClass));
+
+    }
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Iterable<Object[]> generateTestParameters() {
+        return Arrays.asList(new Object[][]{
+                {__.V().count(), countStep(Vertex.class), Collections.emptyList()},
+                {__.V().count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().as("a").count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                //
+                {__.V(), __.V(), Collections.emptyList()},
+                {__.V().out().count(), __.V().out().count(), Collections.emptyList()},
+                {__.count(), __.count(), Collections.emptyList()},
+        });
+    }
+}


[2/6] tinkerpop git commit: Generalized TinkerGraphCountStrategy to support GraphStep, MapStep*, CountGlobalStep patterns. Added more test cases to verify complex traversals.

Posted by ok...@apache.org.
Generalized TinkerGraphCountStrategy to support GraphStep,MapStep*,CountGlobalStep patterns. Added more test cases to verify complex traversals.


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

Branch: refs/heads/master
Commit: 87099c8eeb2ce26c8674f3e896e60f34986750a3
Parents: 0ea3b5e
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Nov 2 13:29:02 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Nov 2 13:29:02 2016 -0600

----------------------------------------------------------------------
 .../optimization/TinkerGraphCountStrategy.java  | 45 ++++++++++++++++----
 .../TinkerGraphCountStrategyTest.java           |  8 ++++
 2 files changed, 45 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/87099c8e/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
index d713e21..50e5c18 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategy.java
@@ -19,10 +19,18 @@
 
 package org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.optimization;
 
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
@@ -30,10 +38,19 @@ import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.step.map.TinkerCountGlobalStep;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 
 /**
+ * This strategy will do a direct {@link org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerHelper#getVertices}
+ * size call if the traversal is a count of the vertices and edges of the graph or a one-to-one map chain thereof.
+ *
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @example <pre>
+ * g.V().count()               // is replaced by TinkerCountGlobalStep
+ * g.V().map(out()).count()    // is replaced by TinkerCountGlobalStep
+ * g.E().label().count()       // is replaced by TinkerCountGlobalStep
+ * </pre>
  */
 public final class TinkerGraphCountStrategy extends AbstractTraversalStrategy<TraversalStrategy.ProviderOptimizationStrategy> implements TraversalStrategy.ProviderOptimizationStrategy {
 
@@ -44,15 +61,27 @@ public final class TinkerGraphCountStrategy extends AbstractTraversalStrategy<Tr
 
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
-        if (traversal.getParent() instanceof EmptyStep &&
-                !TraversalHelper.onGraphComputer(traversal) &&
-                2 == traversal.getSteps().size() &&
-                traversal.getStartStep() instanceof GraphStep &&
-                traversal.getEndStep() instanceof CountGlobalStep) {
-            final Class<? extends Element> elementClass = ((GraphStep) traversal.getStartStep()).getReturnClass();
-            TraversalHelper.removeAllSteps(traversal);
-            traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass));
+        if (!(traversal.getParent() instanceof EmptyStep) || TraversalHelper.onGraphComputer(traversal))
+            return;
+        final List<Step> steps = traversal.getSteps();
+        if (steps.size() < 2 ||
+                !(steps.get(0) instanceof GraphStep) ||
+                0 != ((GraphStep) steps.get(0)).getIds().length ||
+                !(steps.get(steps.size() - 1) instanceof CountGlobalStep))
+            return;
+        for (int i = 1; i < steps.size() - 1; i++) {
+            final Step current = steps.get(i);
+            if (!(current instanceof MapStep ||
+                    current instanceof IdentityStep ||
+                    current instanceof NoOpBarrierStep ||
+                    current instanceof CollectingBarrierStep) ||
+                    (current instanceof TraversalParent &&
+                            TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateStep), (TraversalParent) current)))
+                return;
         }
+        final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass();
+        TraversalHelper.removeAllSteps(traversal);
+        traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/87099c8e/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
index 296133a..5283ee6 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
@@ -38,6 +38,8 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
 import static org.junit.Assert.assertEquals;
 
 /**
@@ -79,10 +81,16 @@ public class TinkerGraphCountStrategyTest {
                 {__.V().count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
                 {__.V().as("a").count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
                 {__.V().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().map(out()).count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().map(out()).identity().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().map(out().groupCount()).identity().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().label().map(s -> s.get().length()).count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
+                {__.V().as("a").map(select("a")).count(), countStep(Vertex.class),TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
                 //
                 {__.V(), __.V(), Collections.emptyList()},
                 {__.V().out().count(), __.V().out().count(), Collections.emptyList()},
                 {__.count(), __.count(), Collections.emptyList()},
+                {__.V().map(out().groupCount("m")).identity().count().as("a"), __.V().map(out().groupCount("m")).identity().count().as("a"), Collections.emptyList()},
         });
     }
 }


[5/6] 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/d95f0a86
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d95f0a86
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d95f0a86

Branch: refs/heads/master
Commit: d95f0a86cc1d121057c13b321125403b167676ea
Parents: c9ec579
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Nov 4 06:13:20 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Nov 4 06:13:20 2016 -0600

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


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d95f0a86/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 83bec7c..98ed480 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.4 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Added `TinkerGraphCountStrategy` which translates `g.V().map*.count()` patterns into direct `Map.size()` calls in `TinkerGraph`.
 * Improved ability to release resources in `GraphProvider` instances in the test suite.
 * Added a `force` option for killing sessions without waiting for transaction close or timeout of a currently running job or multiple jobs.
 * Deprecated `Session.kill()` and `Session.manualKill()`.


[3/6] tinkerpop git commit: another test case to be certain about GraphStep.getIds().

Posted by ok...@apache.org.
another test case to be certain about GraphStep.getIds().


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

Branch: refs/heads/master
Commit: 3badc8ef7079dfe6e75c632ac67d12a19a825450
Parents: 87099c8
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Nov 2 13:33:25 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Nov 2 13:33:25 2016 -0600

----------------------------------------------------------------------
 .../strategy/optimization/TinkerGraphCountStrategyTest.java         | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3badc8ef/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
index 5283ee6..0db378b 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphCountStrategyTest.java
@@ -89,6 +89,7 @@ public class TinkerGraphCountStrategyTest {
                 //
                 {__.V(), __.V(), Collections.emptyList()},
                 {__.V().out().count(), __.V().out().count(), Collections.emptyList()},
+                {__.V(1).count(), __.V(1).count(), Collections.emptyList()},
                 {__.count(), __.count(), Collections.emptyList()},
                 {__.V().map(out().groupCount("m")).identity().count().as("a"), __.V().map(out().groupCount("m")).identity().count().as("a"), Collections.emptyList()},
         });


[6/6] tinkerpop git commit: Merge branch 'tp32'

Posted by ok...@apache.org.
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/f8220be5
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f8220be5
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f8220be5

Branch: refs/heads/master
Commit: f8220be5a4aedfb62bf88702cfb9fb4781e99e3e
Parents: 1544744 d95f0a8
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Nov 4 07:06:14 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Nov 4 07:06:14 2016 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../gremlin/neo4j/structure/Neo4jGraph.java     |  1 -
 .../step/map/TinkerCountGlobalStep.java         | 75 +++++++++++++++
 .../optimization/TinkerGraphCountStrategy.java  | 95 +++++++++++++++++++
 .../tinkergraph/structure/TinkerGraph.java      | 14 +--
 .../tinkergraph/structure/TinkerHelper.java     |  8 ++
 .../TinkerGraphCountStrategyTest.java           | 97 ++++++++++++++++++++
 7 files changed, 284 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


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

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f8220be5/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
----------------------------------------------------------------------
diff --cc neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
index d4327d1,5226149..8224d47
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
@@@ -67,8 -68,9 +67,7 @@@ import java.util.stream.Stream
  @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_PROCESS_STANDARD)
  @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
  @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
 -@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
  @Graph.OptIn("org.apache.tinkerpop.gremlin.neo4j.NativeNeo4jSuite")
- @Graph.OptIn("org.apache.tinkerpop.gremlin.neo4j.process.traversal.strategy.Neo4jStrategySuite")
  public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
  
      public static final Logger LOGGER = LoggerFactory.getLogger(Neo4jGraph.class);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f8220be5/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --cc tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index a1044ee,e498b30..2f73639
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@@ -66,7 -69,7 +67,6 @@@ import java.util.stream.Stream
  @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_PROCESS_COMPUTER)
  @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
  @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
- @Graph.OptIn("org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.TinkerGraphStrategySuite")
 -@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
  public final class TinkerGraph implements Graph {
  
      static {


[4/6] tinkerpop git commit: Merge branch 'TINKERPOP-1292' into tp32

Posted by ok...@apache.org.
Merge branch 'TINKERPOP-1292' into tp32


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

Branch: refs/heads/master
Commit: c9ec579e9ce6e640406fee4f960552dec36c8e03
Parents: 51a1435 3badc8e
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Nov 4 06:11:16 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Nov 4 06:11:16 2016 -0600

----------------------------------------------------------------------
 .../gremlin/neo4j/structure/Neo4jGraph.java     |  1 -
 .../step/map/TinkerCountGlobalStep.java         | 75 +++++++++++++++
 .../optimization/TinkerGraphCountStrategy.java  | 95 +++++++++++++++++++
 .../tinkergraph/structure/TinkerGraph.java      | 14 +--
 .../tinkergraph/structure/TinkerHelper.java     |  8 ++
 .../TinkerGraphCountStrategyTest.java           | 97 ++++++++++++++++++++
 6 files changed, 283 insertions(+), 7 deletions(-)
----------------------------------------------------------------------