use of org.apache.flink.graph.Edge in project flink by apache.
the class GatherSumApplyConfigurationITCase method testIterationDirectionALL.
@Test
public void testIterationDirectionALL() throws Exception {
/*
* Test that if the direction parameter OUT is given, the iteration works as expected
* (i.e. it gathers information from both IN and OUT edges and neighbors
* When data is gathered from the ALL edges the Gather Sum and Apply functions
* set the set of vertices which are connected to a Vertex through some path as value of that vertex
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
GSAConfiguration parameters = new GSAConfiguration();
parameters.setDirection(EdgeDirection.ALL);
List<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdges();
edges.remove(0);
Graph<Long, HashSet<Long>, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), edges, env).mapVertices(new GatherSumApplyConfigurationITCase.InitialiseHashSetMapper());
DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runGatherSumApplyIteration(new GetReachableVertices(), new FindAllReachableVertices(), new UpdateReachableVertices(), 4, parameters).getVertices();
List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();
expectedResult = "1,[1, 2, 3, 4, 5]\n" + "2,[1, 2, 3, 4, 5]\n" + "3,[1, 2, 3, 4, 5]\n" + "4,[1, 2, 3, 4, 5]\n" + "5,[1, 2, 3, 4, 5]\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testSubGraph.
@SuppressWarnings("serial")
@Test
public void testSubGraph() throws Exception {
/*
* Test subgraph:
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
DataSet<Edge<Long, Long>> data = graph.subgraph(new FilterFunction<Vertex<Long, Long>>() {
public boolean filter(Vertex<Long, Long> vertex) throws Exception {
return (vertex.getValue() > 2);
}
}, new FilterFunction<Edge<Long, Long>>() {
public boolean filter(Edge<Long, Long> edge) throws Exception {
return (edge.getValue() > 34);
}
}).getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "3,5,35\n" + "4,5,45\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testDifference.
@Test
public void testDifference() throws Exception {
/*Test difference() method by checking the output for getEdges() on the resultant graph
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
Graph<Long, Long, Long> graph2 = Graph.fromDataSet(TestGraphUtils.getLongLongVertexDataDifference(env), TestGraphUtils.getLongLongEdgeDataDifference(env), env);
graph = graph.difference(graph2);
List<Edge<Long, Long>> result = graph.getEdges().collect();
expectedResult = "4,5,45\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testIntersect.
@Test
public final void testIntersect() throws Exception {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
@SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>();
edges1.add(new Edge<>(1L, 3L, 12L));
// needs to be in the output
edges1.add(new Edge<>(1L, 3L, 13L));
edges1.add(new Edge<>(1L, 3L, 14L));
@SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>();
edges2.add(new Edge<>(1L, 3L, 13L));
Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env);
Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env);
Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true);
List<Vertex<Long, NullValue>> vertices = new ArrayList<>();
List<Edge<Long, Long>> edges = new ArrayList<>();
intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices));
intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges));
env.execute();
String expectedVertices = "1,(null)\n" + "3,(null)\n";
String expectedEdges = "1,3,13\n";
compareResultAsTuples(vertices, expectedVertices);
compareResultAsTuples(edges, expectedEdges);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testRemoveBothInvalidVertices.
@Test
public void testRemoveBothInvalidVertices() throws Exception {
/*
* Test removeVertices() -- remove two invalid vertices
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
List<Vertex<Long, Long>> verticesToBeRemoved = new ArrayList<>();
verticesToBeRemoved.add(new Vertex<>(6L, 6L));
verticesToBeRemoved.add(new Vertex<>(7L, 7L));
graph = graph.removeVertices(verticesToBeRemoved);
DataSet<Edge<Long, Long>> data = graph.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
compareResultAsTuples(result, expectedResult);
}
Aggregations