use of org.apache.flink.graph.Edge in project flink by apache.
the class MapEdgesITCase method testWithStringValue.
@Test
public void testWithStringValue() throws Exception {
/*
* Test mapEdges() and change the value type to String
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
DataSet<Edge<Long, String>> mappedEdges = graph.mapEdges(new ToStringMapper()).getEdges();
List<Edge<Long, String>> result = mappedEdges.collect();
expectedResult = "1,2,string(12)\n" + "1,3,string(13)\n" + "2,3,string(23)\n" + "3,4,string(34)\n" + "3,5,string(35)\n" + "4,5,string(45)\n" + "5,1,string(51)\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testUnion.
@Test
public void testUnion() throws Exception {
/*
* Test union()
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
List<Vertex<Long, Long>> vertices = new ArrayList<>();
List<Edge<Long, Long>> edges = new ArrayList<>();
vertices.add(new Vertex<>(6L, 6L));
edges.add(new Edge<>(6L, 1L, 61L));
graph = graph.union(Graph.fromCollection(vertices, edges, env));
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" + "6,1,61\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testIntersectWithPairs.
@Test
public final void testIntersectWithPairs() throws Exception {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
@SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>();
edges1.add(new Edge<>(1L, 3L, 12L));
edges1.add(new Edge<>(1L, 3L, 13L));
// output
edges1.add(new Edge<>(1L, 3L, 13L));
// output
edges1.add(new Edge<>(1L, 3L, 13L));
// output
edges1.add(new Edge<>(1L, 3L, 14L));
@SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>();
// output
edges2.add(new Edge<>(1L, 3L, 13L));
// output
edges2.add(new Edge<>(1L, 3L, 13L));
// output
edges2.add(new Edge<>(1L, 3L, 14L));
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, false);
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" + "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,14\n" + "1,3,14";
compareResultAsTuples(vertices, expectedVertices);
compareResultAsTuples(edges, expectedEdges);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testReverse.
@Test
public void testReverse() throws Exception {
/*
* Test reverse()
*/
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.reverse().getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "2,1,12\n" + "3,1,13\n" + "3,2,23\n" + "4,3,34\n" + "5,3,35\n" + "5,4,45\n" + "1,5,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testFilterVertices.
@SuppressWarnings("serial")
@Test
public void testFilterVertices() throws Exception {
/*
* Test filterOnVertices:
*/
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.filterOnVertices(new FilterFunction<Vertex<Long, Long>>() {
public boolean filter(Vertex<Long, Long> vertex) throws Exception {
return (vertex.getValue() > 2);
}
}).getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "3,4,34\n" + "3,5,35\n" + "4,5,45\n";
compareResultAsTuples(result, expectedResult);
}
Aggregations