/** * Constructs new edges by joining the edges of the first graph with the new * vertices. * * @param newVertices vertex set of the resulting graph collection * @return edges set only connect vertices in {@code newVertices} * @see Difference * @see Intersection */ @Override protected DataSet<Edge> computeNewEdges(DataSet<Vertex> newVertices) { return firstCollection.getEdges().join(newVertices) .where(new SourceId<>()) .equalTo(new Id<>()) .with(new LeftSide<>()) .join(newVertices) .where(new TargetId<>()) .equalTo(new Id<>()) .with(new LeftSide<>()) .distinct(new Id<>()); } }
/** * {@inheritDoc} */ @Override public LogicalGraph sample(LogicalGraph graph) { graph = new DistinctVertexDegrees( DEGREE_PROPERTY_KEY, IN_DEGREE_PROPERTY_KEY, OUT_DEGREE_PROPERTY_KEY, true).execute(graph); DataSet<Vertex> newVertices = graph.getVertices() .filter(new LimitedDegreeVertexRandomFilter<>( sampleSize, randomSeed, degreeThreshold, degreeType)) .map(new PropertyRemover<>(DEGREE_PROPERTY_KEY)) .map(new PropertyRemover<>(IN_DEGREE_PROPERTY_KEY)) .map(new PropertyRemover<>(OUT_DEGREE_PROPERTY_KEY)); DataSet<Edge> newEdges = graph.getEdges() .join(newVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new LeftSide<>()) .join(newVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new LeftSide<>()); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(graph.getGraphHead(), newVertices, newEdges); }
/** * Constructs new edges by joining the edges of the first graph with the new * vertices. * * @param newVertices vertex set of the resulting graph collection * @return edges set only connect vertices in {@code newVertices} * @see Difference * @see Intersection */ @Override protected DataSet<Edge> computeNewEdges(DataSet<Vertex> newVertices) { return firstCollection.getEdges().join(newVertices) .where(new SourceId<>()) .equalTo(new Id<>()) .with(new LeftSide<>()) .join(newVertices) .where(new TargetId<>()) .equalTo(new Id<>()) .with(new LeftSide<>()) .distinct(new Id<>()); } }
@Override public LogicalGraph executeInGelly(Graph<GradoopId, GradoopId, NullValue> graph) throws Exception { DataSet<Vertex> annotatedVertices = new org.apache.flink.graph.library.ConnectedComponents< GradoopId, GradoopId, NullValue>(maxIterations).run(graph) .join(currentGraph.getVertices()) .where(0).equalTo(new Id<>()) .with(new GellyVertexValueToVertexPropertyJoin(propertyKey)); DataSet<Edge> edges = currentGraph.getEdges(); if (annotateEdges) { edges = edges.join(annotatedVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new VertexPropertyToEdgePropertyJoin(propertyKey)) .join(annotatedVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new VertexPropertyToEdgePropertyJoin(propertyKey)); } return currentGraph.getConfig().getLogicalGraphFactory().fromDataSets( currentGraph.getGraphHead(), annotatedVertices, edges); } }
/** * {@inheritDoc} */ @Override public LogicalGraph sample(LogicalGraph graph) { DataSet<Vertex> sampledVertices = graph.getVertices() .map(new VertexRandomMarkedMap(sampleSize, randomSeed, PROPERTY_KEY_SAMPLED)); DataSet<Edge> newEdges = graph.getEdges() .join(sampledVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new EdgeSourceVertexJoin(PROPERTY_KEY_SAMPLED)) .join(sampledVertices) .where(1).equalTo(new Id<>()) .with(new EdgeTargetVertexJoin(PROPERTY_KEY_SAMPLED)) .filter(new EdgesWithSampledVerticesFilter(neighborType)) .map(new Value0Of3<>()); graph = graph.getFactory().fromDataSets(graph.getVertices(), newEdges); graph = new FilterVerticesWithDegreeOtherThanGiven(0L).execute(graph); return graph; }
@Override public LogicalGraph executeInGelly(Graph<GradoopId, GradoopId, NullValue> graph) throws Exception { DataSet<Vertex> annotatedVertices = new org.apache.flink.graph.library.ConnectedComponents< GradoopId, GradoopId, NullValue>(maxIterations).run(graph) .join(currentGraph.getVertices()) .where(0).equalTo(new Id<>()) .with(new GellyVertexValueToVertexPropertyJoin(propertyKey)); DataSet<Edge> edges = currentGraph.getEdges(); if (annotateEdges) { edges = edges.join(annotatedVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new VertexPropertyToEdgePropertyJoin(propertyKey)) .join(annotatedVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new VertexPropertyToEdgePropertyJoin(propertyKey)); } return currentGraph.getConfig().getLogicalGraphFactory().fromDataSets( currentGraph.getGraphHead(), annotatedVertices, edges); }
/** * Returns the subgraph of the given supergraph that is induced by the * vertices that fulfil the given filter function. * * @param superGraph supergraph * @return vertex-induced subgraph */ private LG vertexInducedSubgraph(LG superGraph) { DataSet<V> filteredVertices = superGraph.getVertices().filter(vertexFilterFunction); DataSet<E> newEdges = superGraph.getEdges() .join(filteredVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new LeftSide<>()) .join(filteredVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new LeftSide<>()); return superGraph.getFactory().fromDataSets(filteredVertices, newEdges); }
/** * Returns the subgraph of the given supergraph that is induced by the * vertices that fulfil the given filter function. * * @param superGraph supergraph * @return vertex-induced subgraph */ private LG vertexInducedSubgraph(LG superGraph) { DataSet<V> filteredVertices = superGraph.getVertices().filter(vertexFilterFunction); DataSet<E> newEdges = superGraph.getEdges() .join(filteredVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new LeftSide<>()) .join(filteredVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new LeftSide<>()); return superGraph.getFactory().fromDataSets(filteredVertices, newEdges); }
/** * Apply filtering functions to the graph and return a sub-graph that * satisfies the predicates for both vertices and edges. * * @param vertexFilter the filter function for vertices. * @param edgeFilter the filter function for edges. * @return the resulting sub-graph. */ public Graph<K, VV, EV> subgraph(FilterFunction<Vertex<K, VV>> vertexFilter, FilterFunction<Edge<K, EV>> edgeFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<>()).name("Subgraph"); DataSet<Edge<K, EV>> filteredEdges = remainingEdges.filter(edgeFilter); return new Graph<>(filteredVertices, filteredEdges, this.context); }
/** * Apply filtering functions to the graph and return a sub-graph that * satisfies the predicates for both vertices and edges. * * @param vertexFilter the filter function for vertices. * @param edgeFilter the filter function for edges. * @return the resulting sub-graph. */ public Graph<K, VV, EV> subgraph(FilterFunction<Vertex<K, VV>> vertexFilter, FilterFunction<Edge<K, EV>> edgeFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<K, VV, EV>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<K, VV, EV>()).name("Subgraph"); DataSet<Edge<K, EV>> filteredEdges = remainingEdges.filter(edgeFilter); return new Graph<>(filteredVertices, filteredEdges, this.context); }
@Override public LogicalGraph sample(LogicalGraph graph) { DataSet<Vertex> sampledVertices = graph.getVertices() .map(new VertexRandomMarkedMap(sampleSize, randomSeed, PROPERTY_KEY_SAMPLED)); DataSet<Edge> newEdges = graph.getEdges() .join(sampledVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new EdgeSourceVertexJoin(PROPERTY_KEY_SAMPLED)) .join(sampledVertices) .where(1).equalTo(new Id<>()) .with(new EdgeTargetVertexJoin(PROPERTY_KEY_SAMPLED)) .filter(new EdgesWithSampledVerticesFilter(neighborType)) .map(new Value0Of3<>()); graph = graph.getFactory().fromDataSets(graph.getVertices(), newEdges); graph = new FilterVerticesWithDegreeOtherThanGiven(0L).execute(graph); return graph; } }
/** * Apply filtering functions to the graph and return a sub-graph that * satisfies the predicates for both vertices and edges. * * @param vertexFilter the filter function for vertices. * @param edgeFilter the filter function for edges. * @return the resulting sub-graph. */ public Graph<K, VV, EV> subgraph(FilterFunction<Vertex<K, VV>> vertexFilter, FilterFunction<Edge<K, EV>> edgeFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<>()).name("Subgraph"); DataSet<Edge<K, EV>> filteredEdges = remainingEdges.filter(edgeFilter); return new Graph<>(filteredVertices, filteredEdges, this.context); }
/** * {@inheritDoc} */ @Override public LogicalGraph sample(LogicalGraph graph) { DataSet<Vertex> newVertices = graph.getVertices() .filter(new RandomFilter<>(sampleSize, randomSeed)); DataSet<Edge> newEdges = graph.getEdges() .join(newVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new LeftSide<>()) .join(newVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new LeftSide<>()); return graph.getConfig().getLogicalGraphFactory().fromDataSets(newVertices, newEdges); }
/** * Apply a filtering function to the graph and return a sub-graph that * satisfies the predicates only for the vertices. * * @param vertexFilter the filter function for vertices. * @return the resulting sub-graph. */ public Graph<K, VV, EV> filterOnVertices(FilterFunction<Vertex<K, VV>> vertexFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<>()).name("Filter on vertices"); return new Graph<>(filteredVertices, remainingEdges, this.context); }
/** * Apply a filtering function to the graph and return a sub-graph that * satisfies the predicates only for the vertices. * * @param vertexFilter the filter function for vertices. * @return the resulting sub-graph. */ public Graph<K, VV, EV> filterOnVertices(FilterFunction<Vertex<K, VV>> vertexFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<K, VV, EV>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<K, VV, EV>()).name("Filter on vertices"); return new Graph<>(filteredVertices, remainingEdges, this.context); }
/** * Apply a filtering function to the graph and return a sub-graph that * satisfies the predicates only for the vertices. * * @param vertexFilter the filter function for vertices. * @return the resulting sub-graph. */ public Graph<K, VV, EV> filterOnVertices(FilterFunction<Vertex<K, VV>> vertexFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<>()).name("Filter on vertices"); return new Graph<>(filteredVertices, remainingEdges, this.context); }
@Override public LogicalGraph sample(LogicalGraph graph) { DataSet<Vertex> newVertices = graph.getVertices() .filter(new RandomFilter<>(sampleSize, randomSeed)); DataSet<Edge> newEdges = graph.getEdges() .join(newVertices) .where(new SourceId<>()).equalTo(new Id<>()) .with(new LeftSide<>()) .join(newVertices) .where(new TargetId<>()).equalTo(new Id<>()) .with(new LeftSide<>()); return graph.getConfig().getLogicalGraphFactory().fromDataSets(newVertices, newEdges); } }
.equalTo(0) // vertex id .with(new SourceVertexJoinFunction<>()) .join(vertexToRepresentativeMap) .where(1) // target vertex id .equalTo(0) // vertex id
/** * Apply a filtering function to the graph and return a sub-graph that * satisfies the predicates only for the vertices. * * @param vertexFilter the filter function for vertices. * @return the resulting sub-graph. */ public Graph<K, VV, EV> filterOnVertices(FilterFunction<Vertex<K, VV>> vertexFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<>()).name("Filter on vertices"); return new Graph<>(filteredVertices, remainingEdges, this.context); }
/** * Apply filtering functions to the graph and return a sub-graph that * satisfies the predicates for both vertices and edges. * * @param vertexFilter the filter function for vertices. * @param edgeFilter the filter function for edges. * @return the resulting sub-graph. */ public Graph<K, VV, EV> subgraph(FilterFunction<Vertex<K, VV>> vertexFilter, FilterFunction<Edge<K, EV>> edgeFilter) { DataSet<Vertex<K, VV>> filteredVertices = this.vertices.filter(vertexFilter); DataSet<Edge<K, EV>> remainingEdges = this.edges.join(filteredVertices) .where(0).equalTo(0).with(new ProjectEdge<>()) .join(filteredVertices).where(1).equalTo(0) .with(new ProjectEdge<>()).name("Subgraph"); DataSet<Edge<K, EV>> filteredEdges = remainingEdges.filter(edgeFilter); return new Graph<>(filteredVertices, filteredEdges, this.context); }