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/03/25 23:23:00 UTC

incubator-tinkerpop git commit: Made it so that GraphFilters are a Feature and a provider can NOT supportGraphFilter() is they choose. This will make moving forward with 3.2.0 much easier for lots of providers as the GraphFilter implementation is pretty

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1236 930ab25d5 -> e8c4f8fd9


Made it so that GraphFilters are a Feature and a provider can NOT supportGraphFilter() is they choose. This will make moving forward with 3.2.0 much easier for lots of providers as the GraphFilter implementation is pretty heavy weight. Added GraphComputerTest cases to ensure that exception messages are correct for those providers that do not support GraphFilters. Updated upgrade doc so providers know they can kick that can down the road if they wish.


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

Branch: refs/heads/TINKERPOP-1236
Commit: e8c4f8fd9968ca7870aa578db72fcbed2f8fe5cb
Parents: 930ab25
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Mar 25 16:22:53 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Mar 25 16:22:53 2016 -0600

----------------------------------------------------------------------
 .../upgrade/release-3.2.x-incubating.asciidoc   |  6 ++-
 .../gremlin/process/computer/GraphComputer.java |  8 ++++
 .../process/computer/GraphComputerTest.java     | 47 ++++++++++++++++++--
 3 files changed, 57 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e8c4f8fd/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.2.x-incubating.asciidoc b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
index d252435..d28669e 100644
--- a/docs/src/upgrade/release-3.2.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
@@ -337,12 +337,16 @@ then there is no immediate action required on their part to remain TinkerPop-com
 their `InputFormat` or `InputRDD` implementation to be `GraphFilterAware` and handle the `GraphFilter` filtering at the disk/database
 level. It is advisable to do so in order to reduce OLAP load times and memory/GC usage.
 
-* If the graph system provider has their own `GraphComputer` implementation, then they will need to implement the two new methods
+* If the graph system provider has their own `GraphComputer` implementation, then they should implement the two new methods
 and ensure that `GraphFilter` is processed correctly. There is a new test case called `GraphComputerTest.shouldSupportGraphFilter()`
 which ensures the semantics of `GraphFilter` are handled correctly. For a "quick and easy" way to move forward, look to
 `GraphFilterInputFormat` as a way of wrapping an existing `InputFormat` to do filtering prior to `VertexProgram` or `MapReduce`
 execution.
 
+NOTE: To quickly move forward, the `GraphComputer` implementation can simply set `GraphComputer.Features.supportsGraphFilter()`
+to `false` and ensure that `GraphComputer.vertices()` and `GraphComputer.edges()` throws `GraphComputer.Exceptions.graphFilterNotSupported()`.
+This is not recommended as its best to support `GraphFilter`.
+
 See: link:https://issues.apache.org/jira/browse/TINKERPOP-962[TINKERPOP-962]
 
 Job Chaining and GraphComputer

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e8c4f8fd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
index ddb09a0..50c8015 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
@@ -207,6 +207,10 @@ public interface GraphComputer {
             return true;
         }
 
+        public default boolean supportsGraphFilter() {
+            return true;
+        }
+
         /**
          * Supports {@link VertexProgram} and {@link MapReduce} parameters to be direct referenced Java objects (no serialization required).
          * This is typically true for single machine graph computer engines. For cluster oriented graph computers, this is typically false.
@@ -233,6 +237,10 @@ public interface GraphComputer {
             return new UnsupportedOperationException("The edges and vertices of an adjacent vertex can not be read or updated");
         }
 
+        public static UnsupportedOperationException graphFilterNotSupported() {
+            return new UnsupportedOperationException("The computer does not support graph filter");
+        }
+
         public static IllegalArgumentException providedKeyIsNotAnElementComputeKey(final String key) {
             return new IllegalArgumentException("The provided key is not an element compute key: " + key);
         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e8c4f8fd/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
index 6ffdbbc..520c611 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
@@ -78,7 +78,8 @@ import static org.junit.Assert.fail;
         "vertexPropertiesCanNotBeUpdatedInMapReduce",
         "computerRequiresMoreWorkersThanSupported",
         "vertexFilterAccessesIncidentEdges",
-        "edgeFilterAccessesAdjacentVertices"
+        "edgeFilterAccessesAdjacentVertices",
+        "graphFilterNotSupported"
 })
 @ExceptionCoverage(exceptionClass = Memory.Exceptions.class, methods = {
         "memoryKeyCanNotBeEmpty",
@@ -125,6 +126,22 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
         } catch (Exception ex) {
             validateException(Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(BadGraphComputer.class), ex);
         }
+        if (!new BadGraphComputer().features().supportsGraphFilter()) {
+            try {
+                new BadGraphComputer().vertices(__.hasLabel("software"));
+                fail("Should throw an unsupported operation exception");
+            } catch (final UnsupportedOperationException e) {
+                assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage());
+            }
+            try {
+                new BadGraphComputer().edges(__.bothE());
+                fail("Should throw an unsupported operation exception");
+            } catch (final UnsupportedOperationException e) {
+                assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage());
+            }
+        } else {
+            fail("Should not support graph filter: " + BadGraphComputer.class);
+        }
     }
 
     public static class BadGraphComputer implements GraphComputer {
@@ -156,12 +173,12 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
 
         @Override
         public GraphComputer vertices(final Traversal<Vertex, Vertex> vertexFilter) {
-            return null;
+            throw GraphComputer.Exceptions.graphFilterNotSupported();
         }
 
         @Override
         public GraphComputer edges(final Traversal<Vertex, Edge> edgeFilter) {
-            return null;
+            throw GraphComputer.Exceptions.graphFilterNotSupported();
         }
 
         @Override
@@ -174,6 +191,14 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
             return null;
         }
 
+        public GraphComputer.Features features() {
+            return new Features() {
+                @Override
+                public boolean supportsGraphFilter() {
+                    return false;
+                }
+            };
+        }
     }
     /////////////////////////////////////////////
 
@@ -1554,6 +1579,22 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
     @Test
     @LoadGraphWith(MODERN)
     public void shouldSupportGraphFilter() throws Exception {
+        // if the graph computer does not support graph filter, then make sure its exception handling is correct
+        if (!graphProvider.getGraphComputer(graph).features().supportsGraphFilter()) {
+            try {
+                graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software"));
+                fail("Should throw an unsupported operation exception");
+            } catch (final UnsupportedOperationException e) {
+                assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage());
+            }
+            try {
+                graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(10));
+                fail("Should throw an unsupported operation exception");
+            } catch (final UnsupportedOperationException e) {
+                assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage());
+            }
+            return;
+        }
         /// VERTEX PROGRAM
         graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).program(new VertexProgramM(VertexProgramM.SOFTWARE_ONLY)).submit().get();
         graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).program(new VertexProgramM(VertexProgramM.PEOPLE_ONLY)).submit().get();