use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testAddExistingEdge.
@Test
public void testAddExistingEdge() throws Exception {
/*
* Test addEdge() -- add already existing edge
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
graph = graph.addEdge(new Vertex<>(1L, 1L), new Vertex<>(2L, 2L), 12L);
DataSet<Edge<Long, Long>> data = graph.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "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);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testRemoveEdges.
@Test
public void testRemoveEdges() throws Exception {
/*
* Test removeEdges() -- simple case
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
List<Edge<Long, Long>> edgesToBeRemoved = new ArrayList<>();
edgesToBeRemoved.add(new Edge<>(5L, 1L, 51L));
edgesToBeRemoved.add(new Edge<>(2L, 3L, 23L));
// duplicate edge should be preserved in output
graph = graph.addEdge(new Vertex<>(1L, 1L), new Vertex<>(2L, 2L), 12L);
graph = graph.removeEdges(edgesToBeRemoved);
DataSet<Edge<Long, Long>> data = graph.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "1,2,12\n" + "1,3,13\n" + "3,4,34\n" + "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 GraphMutationsITCase method testRemoveVertex.
@Test
public void testRemoveVertex() throws Exception {
/*
* Test removeVertex() -- simple case
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
graph = graph.removeVertex(new Vertex<>(5L, 5L));
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";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testRemoveOneValidOneInvalidVertex.
@Test
public void testRemoveOneValidOneInvalidVertex() throws Exception {
/*
* Test removeVertices() -- remove one invalid vertex and a valid one
*/
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<>(1L, 1L));
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 = "2,3,23\n" + "3,4,34\n" + "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 MapEdgesITCase method testWithSameValue.
@Test
public void testWithSameValue() throws Exception {
/*
* Test mapEdges() keeping the same value type
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
DataSet<Edge<Long, Long>> mappedEdges = graph.mapEdges(new AddOneMapper()).getEdges();
List<Edge<Long, Long>> result = mappedEdges.collect();
expectedResult = "1,2,13\n" + "1,3,14\n" + "2,3,24\n" + "3,4,35\n" + "3,5,36\n" + "4,5,46\n" + "5,1,52\n";
compareResultAsTuples(result, expectedResult);
}
Aggregations