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 2015/08/24 22:22:34 UTC
incubator-tinkerpop git commit: Reintroduced LoopTraversal for
times(x) queries. Way more efficient than @dkuppitz change ofto
loops().is(gt(x)). In general -- AbstractLambdaTraversals are used for
efficient static calls --- making and executing a 'real
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master c985fac6b -> bcf91531c
Reintroduced LoopTraversal for times(x) queries. Way more efficient than @dkuppitz change ofto loops().is(gt(x)). In general -- AbstractLambdaTraversals are used for efficient static calls --- making and executing a 'real traversal' for in such situations is too expensive.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/bcf91531
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/bcf91531
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/bcf91531
Branch: refs/heads/master
Commit: bcf91531c088d00d8808172b6938ded8a9a7fc55
Parents: c985fac
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Aug 24 14:22:30 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Aug 24 14:22:30 2015 -0600
----------------------------------------------------------------------
.../traversal/dsl/graph/GraphTraversal.java | 2 +-
.../process/traversal/lambda/LoopTraversal.java | 57 ++++++++++++++++++++
.../traversal/step/sideEffect/ProfileTest.java | 15 +-----
3 files changed, 60 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bcf91531/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index b58501e..a643e48 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -872,7 +872,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
}
public default GraphTraversal<S, E> times(final int maxLoops) {
- return this.until(__.loops().is(maxLoops));
+ return this.until(new LoopTraversal<>(maxLoops));
}
public default <E2> GraphTraversal<S, E2> local(final Traversal<?, E2> localTraversal) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bcf91531/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/LoopTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/LoopTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/LoopTraversal.java
new file mode 100644
index 0000000..9c37853
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/LoopTraversal.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one
+ * * or more contributor license agreements. See the NOTICE file
+ * * distributed with this work for additional information
+ * * regarding copyright ownership. The ASF licenses this file
+ * * to you under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance
+ * * with the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing,
+ * * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * * KIND, either express or implied. See the License for the
+ * * specific language governing permissions and limitations
+ * * under the License.
+ *
+ */
+
+package org.apache.tinkerpop.gremlin.process.traversal.lambda;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class LoopTraversal<S, E> extends AbstractLambdaTraversal<S, E> {
+
+ private final long maxLoops;
+ private boolean allow = false;
+
+ public LoopTraversal(final long maxLoops) {
+ this.maxLoops = maxLoops;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return this.allow;
+ }
+
+ @Override
+ public void addStart(final Traverser<S> start) {
+ this.allow = start.loops() >= this.maxLoops;
+ }
+
+ @Override
+ public String toString() {
+ return "loops(" + this.maxLoops + ')';
+ }
+
+ @Override
+ public int hashCode() {
+ return this.getClass().hashCode() ^ Long.hashCode(this.maxLoops);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bcf91531/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/ProfileTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/ProfileTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/ProfileTest.java
index 84fa2bb..390678e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/ProfileTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/ProfileTest.java
@@ -209,24 +209,13 @@ public abstract class ProfileTest extends AbstractGremlinProcessTest {
assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);
// Test the nested global metrics of the repeat step
- final Metrics loopsStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[0];
- assertEquals(96, loopsStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
- assertEquals(96, loopsStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
- assertTrue("Times should be positive.", loopsStepNestedInRepeat.getDuration(TimeUnit.MICROSECONDS) >= 0);
-
- final Metrics isStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[1];
- // TODO: the following 2 assertions are pretty questionable (see issue TINKERPOP3-763)
- assertEquals(0, isStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
- assertEquals(0, isStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
- assertTrue("Times should be positive.", isStepNestedInRepeat.getDuration(TimeUnit.MICROSECONDS) >= 0);
-
- final Metrics vertexStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[2];
+ final Metrics vertexStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[0];
assertEquals(114, vertexStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
assertNotEquals(0, vertexStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
assertTrue("Count should be greater than traversers.", vertexStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > vertexStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
assertTrue("Times should be positive.", vertexStepNestedInRepeat.getDuration(TimeUnit.MICROSECONDS) >= 0);
- final Metrics repeatEndStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[3];
+ final Metrics repeatEndStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[1];
assertEquals(72, repeatEndStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
assertNotEquals(0, repeatEndStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
assertTrue("Count should be greater than traversers.", repeatEndStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > repeatEndStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());