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/02/06 20:54:42 UTC

[11/30] incubator-tinkerpop git commit: Added a state-based test case to GraphFilter. About to run this thing on the Blade cluster against Friendster to see how well we do now.

Added a state-based test case to GraphFilter. About to run this thing on the Blade cluster against Friendster to see how well we do now.


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

Branch: refs/heads/master
Commit: e4cf925b496ee250f7dca48d094e8b93816ca075
Parents: 72e388c
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Feb 2 13:24:45 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Feb 2 13:24:45 2016 -0700

----------------------------------------------------------------------
 .../gremlin/process/computer/GraphFilter.java   | 11 +--
 .../process/computer/GraphFilterTest.java       | 83 ++++++++++++++++++++
 2 files changed, 89 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e4cf925b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
index 3813320..f38ce90 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
@@ -45,9 +45,10 @@ public final class GraphFilter implements Cloneable, Serializable {
     private Traversal.Admin<Vertex, Vertex> vertexFilter = null;
     private Traversal.Admin<Vertex, Edge> edgeFilter = null;
 
-    private Direction allowedEdgeDirection = Direction.BOTH;
-    private Set<String> allowedEdgeLabels = new HashSet<>();
-    private boolean allowAllRemainingEdges = false;
+    // private boolean dropAllEdges (make this a fast one if the end is limit(0)?)
+    protected Direction allowedEdgeDirection = Direction.BOTH;
+    protected Set<String> allowedEdgeLabels = new HashSet<>();
+    protected boolean allowAllRemainingEdges = false;
 
     public void setVertexFilter(final Traversal<Vertex, Vertex> vertexFilter) {
         this.vertexFilter = vertexFilter.asAdmin().clone();
@@ -127,7 +128,7 @@ public final class GraphFilter implements Cloneable, Serializable {
             return vertex;
         else if (null == vertex)
             return null;
-        else if (!this.hasVertexFilter() || TraversalUtil.test(vertex, this.vertexFilter)) {
+        else if (this.legalVertex(vertex)) {
             if (this.hasEdgeFilter()) {
                 if (!this.allowedEdgeDirection.equals(Direction.BOTH))
                     vertex.dropEdges(this.allowedEdgeDirection.opposite());
@@ -137,7 +138,7 @@ public final class GraphFilter implements Cloneable, Serializable {
                 if (!this.allowAllRemainingEdges) {
                     final Map<String, List<Edge>> outEdges = new HashMap<>();
                     final Map<String, List<Edge>> inEdges = new HashMap<>();
-                    TraversalUtil.applyAll(vertex, this.edgeFilter).forEachRemaining(edge -> {
+                    this.legalEdges(vertex).forEachRemaining(edge -> {
                         if (edge instanceof StarGraph.StarOutEdge) {
                             List<Edge> edges = outEdges.get(edge.label());
                             if (null == edges) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e4cf925b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
new file mode 100644
index 0000000..11091a2
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.computer;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class GraphFilterTest {
+
+    @Test
+    public void shouldHandlePreFilterCorrectly() {
+        final GraphFilter graphFilter = new GraphFilter();
+        graphFilter.setEdgeFilter(__.<Vertex>bothE().limit(0));
+        assertTrue(graphFilter.allowedEdgeLabels.isEmpty());
+        assertEquals(Direction.BOTH, graphFilter.allowedEdgeDirection);
+        assertFalse(graphFilter.allowAllRemainingEdges);
+        //
+        graphFilter.setEdgeFilter(__.<Vertex>bothE("knows").limit(0));
+        assertEquals(1, graphFilter.allowedEdgeLabels.size());
+        assertTrue(graphFilter.allowedEdgeLabels.contains("knows"));
+        assertEquals(Direction.BOTH, graphFilter.allowedEdgeDirection);
+        assertFalse(graphFilter.allowAllRemainingEdges);
+        //
+        graphFilter.setEdgeFilter(__.<Vertex>outE("knows", "created"));
+        assertEquals(2, graphFilter.allowedEdgeLabels.size());
+        assertTrue(graphFilter.allowedEdgeLabels.contains("knows"));
+        assertTrue(graphFilter.allowedEdgeLabels.contains("created"));
+        assertEquals(Direction.OUT, graphFilter.allowedEdgeDirection);
+        assertTrue(graphFilter.allowAllRemainingEdges);
+        //
+        graphFilter.setEdgeFilter(__.<Vertex>inE("knows", "created", "likes"));
+        assertEquals(3, graphFilter.allowedEdgeLabels.size());
+        assertTrue(graphFilter.allowedEdgeLabels.contains("knows"));
+        assertTrue(graphFilter.allowedEdgeLabels.contains("created"));
+        assertTrue(graphFilter.allowedEdgeLabels.contains("likes"));
+        assertEquals(Direction.IN, graphFilter.allowedEdgeDirection);
+        assertTrue(graphFilter.allowAllRemainingEdges);
+        //
+        graphFilter.setEdgeFilter(__.<Vertex>inE("knows", "created", "likes").has("weight", 1));
+        assertEquals(3, graphFilter.allowedEdgeLabels.size());
+        assertTrue(graphFilter.allowedEdgeLabels.contains("knows"));
+        assertTrue(graphFilter.allowedEdgeLabels.contains("created"));
+        assertTrue(graphFilter.allowedEdgeLabels.contains("likes"));
+        assertEquals(Direction.IN, graphFilter.allowedEdgeDirection);
+        assertFalse(graphFilter.allowAllRemainingEdges);
+    }
+
+    /*@Test
+    public void shouldHandleStarGraph() {
+        final StarGraph graph = StarGraph.open();
+        final Vertex vertex = graph.addVertex("person");
+        for (int i = 0; i < 10; i++) {
+            vertex.addEdge("created", graph.addVertex(i < 5 ? "software" : "hardware"), "weight", 1);
+        }
+        final GraphFilter graphFilter = new GraphFilter();
+    }*/
+}