Java Code Examples for org.apache.flink.graph.Graph#intersect()

The following examples show how to use org.apache.flink.graph.Graph#intersect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphOperationsITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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));
	edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output
	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);
}
 
Example 2
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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));
	edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output
	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);
}
 
Example 3
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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));
	edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output
	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);
}
 
Example 4
Source File: GraphOperationsITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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));
	edges1.add(new Edge<>(1L, 3L, 13L)); // output
	edges1.add(new Edge<>(1L, 3L, 13L)); // output
	edges1.add(new Edge<>(1L, 3L, 14L)); // output

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges2 = new ArrayList<>();
	edges2.add(new Edge<>(1L, 3L, 13L)); // output
	edges2.add(new Edge<>(1L, 3L, 13L)); // output
	edges2.add(new Edge<>(1L, 3L, 14L)); // output

	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);
}
 
Example 5
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@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));
	edges1.add(new Edge<>(1L, 3L, 13L)); // output
	edges1.add(new Edge<>(1L, 3L, 13L)); // output
	edges1.add(new Edge<>(1L, 3L, 14L)); // output

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges2 = new ArrayList<>();
	edges2.add(new Edge<>(1L, 3L, 13L)); // output
	edges2.add(new Edge<>(1L, 3L, 13L)); // output
	edges2.add(new Edge<>(1L, 3L, 14L)); // output

	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);
}
 
Example 6
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@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));
	edges1.add(new Edge<>(1L, 3L, 13L)); // output
	edges1.add(new Edge<>(1L, 3L, 13L)); // output
	edges1.add(new Edge<>(1L, 3L, 14L)); // output

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges2 = new ArrayList<>();
	edges2.add(new Edge<>(1L, 3L, 13L)); // output
	edges2.add(new Edge<>(1L, 3L, 13L)); // output
	edges2.add(new Edge<>(1L, 3L, 14L)); // output

	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);
}