@Override public String toString() { if (!this.hasFilter()) return "graphfilter[none]"; else if (this.hasVertexFilter() && this.hasEdgeFilter()) return "graphfilter[" + this.vertexFilter + "," + this.edgeFilter + "]"; else if (this.hasVertexFilter()) return "graphfilter[" + this.vertexFilter + "]"; else return "graphfilter[" + this.edgeFilter + "]"; } }
@Override public GraphComputer edges(final Traversal<Vertex, Edge> edgeFilter) { this.graphFilter.setEdgeFilter(edgeFilter); return this; }
@Override public GraphComputer vertices(final Traversal<Vertex, Vertex> vertexFilter) { this.graphFilter.setVertexFilter(vertexFilter); return this; }
public TinkerGraphComputerView(final TinkerGraph graph, final GraphFilter graphFilter, final Set<VertexComputeKey> computeKeys) { this.graph = graph; this.computeKeys = new HashMap<>(); computeKeys.forEach(key -> this.computeKeys.put(key.getKey(), key)); this.computeProperties = new ConcurrentHashMap<>(); this.graphFilter = graphFilter; if (this.graphFilter.hasFilter()) { graph.vertices().forEachRemaining(vertex -> { boolean legalVertex = false; if (this.graphFilter.hasVertexFilter() && this.graphFilter.legalVertex(vertex)) { this.legalVertices.add(vertex.id()); legalVertex = true; } if ((legalVertex || !this.graphFilter.hasVertexFilter()) && this.graphFilter.hasEdgeFilter()) { final Set<Object> edges = new HashSet<>(); this.legalEdges.put(vertex.id(), edges); this.graphFilter.legalEdges(vertex).forEachRemaining(edge -> edges.add(edge.id())); } }); } }
public Optional<StarVertex> applyGraphFilter(final GraphFilter graphFilter) { if (!graphFilter.hasFilter()) return Optional.of(this); else if (graphFilter.legalVertex(this)) { if (graphFilter.hasEdgeFilter()) { if (graphFilter.checkEdgeLegality(Direction.OUT).negative()) this.dropEdges(Direction.OUT); if (graphFilter.checkEdgeLegality(Direction.IN).negative()) this.dropEdges(Direction.IN); if (null != this.outEdges) for (final String key : new HashSet<>(this.outEdges.keySet())) { if (graphFilter.checkEdgeLegality(Direction.OUT, key).negative()) this.dropEdges(Direction.OUT, key); if (graphFilter.checkEdgeLegality(Direction.IN, key).negative()) this.dropEdges(Direction.IN, key); final Map<String, List<Edge>> outEdges = new HashMap<>(); final Map<String, List<Edge>> inEdges = new HashMap<>(); graphFilter.legalEdges(this).forEachRemaining(edge -> { if (edge instanceof StarGraph.StarOutEdge) { List<Edge> edges = outEdges.get(edge.label());
public static void storeGraphFilter(final Configuration apacheConfiguration, final org.apache.hadoop.conf.Configuration hadoopConfiguration, final GraphFilter graphFilter) { if (graphFilter.hasFilter()) { VertexProgramHelper.serialize(graphFilter, apacheConfiguration, Constants.GREMLIN_HADOOP_GRAPH_FILTER); hadoopConfiguration.set(Constants.GREMLIN_HADOOP_GRAPH_FILTER, apacheConfiguration.getString(Constants.GREMLIN_HADOOP_GRAPH_FILTER)); } } }
public GraphFilter(final Computer computer) { if (null != computer.getVertices()) this.setVertexFilter(computer.getVertices()); if (null != computer.getEdges()) this.setEdgeFilter(computer.getEdges()); }
private StarGraphGryoSerializer(final Direction edgeDirectionToSerialize) { this(edgeDirectionToSerialize, new GraphFilter()); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) public void shouldHandleBothEdgesGraphFilterOnSelfLoop() { assertEquals(0l, IteratorUtils.count(graph.vertices())); assertEquals(0l, IteratorUtils.count(graph.edges())); // these vertex label, edge label, and property names/values were copied from existing tests StarGraph starGraph = StarGraph.open(); Vertex vertex = starGraph.addVertex(T.label, "person", "name", "furnace"); Edge edge = vertex.addEdge("self", vertex); edge.property("acl", "private"); // traversing a self-loop should yield the edge once for inE/outE // and the edge twice for bothE (one edge emitted two times, not two edges) assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().inE())); assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().outE())); assertEquals(2L, IteratorUtils.count(starGraph.traversal().V().bothE())); // Try a filter that retains BOTH GraphFilter graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.bothE("self")); starGraph = starGraph.applyGraphFilter(graphFilter).get(); // Retest traversal counts after filtering assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().inE())); assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().outE())); assertEquals(2L, IteratorUtils.count(starGraph.traversal().V().bothE())); }
@Override public boolean equals(final Object object) { if (!(object instanceof GraphFilter)) return false; else if (((GraphFilter) object).hasVertexFilter() && !((GraphFilter) object).vertexFilter.equals(this.vertexFilter)) return false; else if (((GraphFilter) object).hasEdgeFilter() && !((GraphFilter) object).edgeFilter.equals(this.edgeFilter)) return false; else return true; }
public static StarGraphGryoSerializer withGraphFilter(final GraphFilter graphFilter) { final StarGraphGryoSerializer serializer = new StarGraphGryoSerializer(Direction.BOTH, graphFilter.clone()); return serializer; } }
public boolean legalEdge(final Vertex vertex, final Edge edge) { return !this.graphFilter.hasEdgeFilter() || this.legalEdges.get(vertex.id()).contains(edge.id()); }
public boolean legalVertex(final Vertex vertex) { return !this.graphFilter.hasVertexFilter() || this.legalVertices.contains(vertex.id()); }
public TinkerGraphComputerView(final TinkerGraph graph, final GraphFilter graphFilter, final Set<VertexComputeKey> computeKeys) { this.graph = graph; this.computeKeys = new HashMap<>(); computeKeys.forEach(key -> this.computeKeys.put(key.getKey(), key)); this.computeProperties = new ConcurrentHashMap<>(); this.graphFilter = graphFilter; if (this.graphFilter.hasFilter()) { graph.vertices().forEachRemaining(vertex -> { boolean legalVertex = false; if (this.graphFilter.hasVertexFilter() && this.graphFilter.legalVertex(vertex)) { this.legalVertices.add(vertex.id()); legalVertex = true; } if ((legalVertex || !this.graphFilter.hasVertexFilter()) && this.graphFilter.hasEdgeFilter()) { final Set<Object> edges = new HashSet<>(); this.legalEdges.put(vertex.id(), edges); this.graphFilter.legalEdges(vertex).forEachRemaining(edge -> edges.add(edge.id())); } }); } }
public Optional<StarVertex> applyGraphFilter(final GraphFilter graphFilter) { if (!graphFilter.hasFilter()) return Optional.of(this); else if (graphFilter.legalVertex(this)) { if (graphFilter.hasEdgeFilter()) { if (graphFilter.checkEdgeLegality(Direction.OUT).negative()) this.dropEdges(Direction.OUT); if (graphFilter.checkEdgeLegality(Direction.IN).negative()) this.dropEdges(Direction.IN); if (null != this.outEdges) for (final String key : new HashSet<>(this.outEdges.keySet())) { if (graphFilter.checkEdgeLegality(Direction.OUT, key).negative()) this.dropEdges(Direction.OUT, key); if (graphFilter.checkEdgeLegality(Direction.IN, key).negative()) this.dropEdges(Direction.IN, key); final Map<String, List<Edge>> outEdges = new HashMap<>(); final Map<String, List<Edge>> inEdges = new HashMap<>(); graphFilter.legalEdges(this).forEachRemaining(edge -> { if (edge instanceof StarGraph.StarOutEdge) { List<Edge> edges = outEdges.get(edge.label());
((GraphFilterAware) inputRDD).setGraphFilter(this.graphFilter); filtered = false; } else if (this.graphFilter.hasFilter()) { filtered = true; } else {
public GraphFilter(final Computer computer) { if (null != computer.getVertices()) this.setVertexFilter(computer.getVertices()); if (null != computer.getEdges()) this.setEdgeFilter(computer.getEdges()); }
@Override public String toString() { return StringFactory.stepString(this, new GraphFilter(this.computer)); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) public void shouldHandleBothEdgesGraphFilterOnSelfLoop() { assertEquals(0l, IteratorUtils.count(graph.vertices())); assertEquals(0l, IteratorUtils.count(graph.edges())); // these vertex label, edge label, and property names/values were copied from existing tests StarGraph starGraph = StarGraph.open(); Vertex vertex = starGraph.addVertex(T.label, "person", "name", "furnace"); Edge edge = vertex.addEdge("self", vertex); edge.property("acl", "private"); // traversing a self-loop should yield the edge once for inE/outE // and the edge twice for bothE (one edge emitted two times, not two edges) assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().inE())); assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().outE())); assertEquals(2L, IteratorUtils.count(starGraph.traversal().V().bothE())); // Try a filter that retains BOTH GraphFilter graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.bothE("self")); starGraph = starGraph.applyGraphFilter(graphFilter).get(); // Retest traversal counts after filtering assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().inE())); assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().outE())); assertEquals(2L, IteratorUtils.count(starGraph.traversal().V().bothE())); }
@Override public boolean equals(final Object object) { if (!(object instanceof GraphFilter)) return false; else if (((GraphFilter) object).hasVertexFilter() && !((GraphFilter) object).vertexFilter.equals(this.vertexFilter)) return false; else if (((GraphFilter) object).hasEdgeFilter() && !((GraphFilter) object).edgeFilter.equals(this.edgeFilter)) return false; else return true; }