Github user okram commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/210#discussion_r52093310
--- Diff:
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
---
@@ -0,0 +1,193 @@
+/*
+ * 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.Traversal;
+import
org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * GraphFilter is used by {@link GraphComputer} implementations to prune
the source graph data being loaded into the OLAP system.
+ * There are two types of filters: a {@link Vertex} filter and an {@link
Edge} filter.
+ * The vertex filter is a {@link Traversal} that can only check the id,
label, and properties of the vertex.
+ * The edge filter is a {@link Traversal} that starts at the vertex are
emits all legal incident edges.
+ * If no vertex filter is provided, then no vertices are filtered. If no
edge filter is provided, then no edges are filtered.
+ * The use of a GraphFilter can greatly reduce the amount of data
processed by the {@link GraphComputer}.
+ * For instance, for {@code g.V().count()}, there is no reason to load
edges, and thus, the edge filter can be {@code bothE().limit(0)}.
+ *
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class GraphFilter implements Cloneable, Serializable {
+
+ public enum Legal {
+ YES, NO, MAYBE;
+
+ public boolean positive() {
+ return this != NO;
+ }
+
+ public boolean negative() {
+ return this == NO;
+ }
+ }
+
+ private Traversal.Admin<Vertex, Vertex> vertexFilter = null;
+ private Traversal.Admin<Vertex, Edge> edgeFilter = null;
+
+ private boolean allowNoEdges = false;
+ private Direction allowedEdgeDirection = Direction.BOTH;
+ private Set<String> allowedEdgeLabels = new HashSet<>();
+ //private boolean allowAllRemainingEdges = false;
+
+ public void setVertexFilter(final Traversal<Vertex, Vertex>
vertexFilter) {
+ if (!TraversalHelper.isLocalVertex(vertexFilter.asAdmin()))
+ throw
GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(vertexFilter);
+ this.vertexFilter = vertexFilter.asAdmin().clone();
+ }
+
+ public void setEdgeFilter(final Traversal<Vertex, Edge> edgeFilter) {
+ if (!TraversalHelper.isLocalStarGraph(edgeFilter.asAdmin()))
+ throw
GraphComputer.Exceptions.edgeFilterAccessesAdjacentVertices(edgeFilter);
+ this.edgeFilter = edgeFilter.asAdmin().clone();
+ if (this.edgeFilter.getEndStep() instanceof RangeGlobalStep && 0
== ((RangeGlobalStep) this.edgeFilter.getEndStep()).getHighRange())
+ this.allowNoEdges = true;
+ else if (this.edgeFilter.getStartStep() instanceof VertexStep) {
+ this.allowedEdgeLabels.clear();
+ this.allowedEdgeLabels.addAll(Arrays.asList(((VertexStep)
this.edgeFilter.getStartStep()).getEdgeLabels()));
+ this.allowedEdgeDirection = ((VertexStep)
this.edgeFilter.getStartStep()).getDirection();
+ //this.allowAllRemainingEdges = 1 ==
this.edgeFilter.getSteps().size();
+ }
+ }
+
+ /*public void compileFilters() {
--- End diff --
I was using `compileFilters()` at first, but then didn't need them. I left
it commented out just in case its something that might pop up in the future.
`GraphFilter` is very new and over this 3.2.0 push, I'm sure we will tweak here
and there. Just want people to know its around.
Regarding the `allowRemainingEdges`. Again, its something I didn't need,
but can easily add if we find a good use case.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---