Java Code Examples for org.apache.flink.graph.utils.VertexToTuple2Map

The following examples show how to use org.apache.flink.graph.utils.VertexToTuple2Map. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: JoinWithVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithVertexSet() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet parameter identical
	 * to the vertex DataSet
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices()
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,8\n" +
		"5,10\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 2
Source Project: Flink-CEPplus   Source File: JoinWithVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLessElements() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet passed as a parameter containing
	 * less elements than the vertex DataSet, but of the same type
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices().first(3)
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 3
@Test
public void testDefaultConfiguration() throws Exception {
	/*
	 * Test Graph's runScatterGatherIteration when configuration parameters are not provided
	 * i.e. degrees and numVertices will be -1, EdgeDirection will be OUT.
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(),
		TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());

	Graph<Long, Long, Long> res = graph.runScatterGatherIteration(
		new MessageFunctionDefault(), new UpdateFunctionDefault(), 5);

	DataSet<Tuple2<Long, Long>> data = res.getVertices().map(new VertexToTuple2Map<>());
	List<Tuple2<Long, Long>> result = data.collect();

	expectedResult = "1,6\n" +
		"2,6\n" +
		"3,6\n" +
		"4,6\n" +
		"5,6";

	compareResultAsTuples(result, expectedResult);
}
 
Example 4
@Test
public void testProgram() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(),
			TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());

	Graph<Long, Long, Long> result = graph.runScatterGatherIteration(
			new MessageFunction(), new UpdateFunction(), 10);

	result.getVertices().map(
		new VertexToTuple2Map<>()).output(
			new DiscardingOutputFormat<>());

	env.execute();
}
 
Example 5
Source Project: flink   Source File: JoinWithVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithVertexSet() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet parameter identical
	 * to the vertex DataSet
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices()
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,8\n" +
		"5,10\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 6
Source Project: flink   Source File: JoinWithVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLessElements() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet passed as a parameter containing
	 * less elements than the vertex DataSet, but of the same type
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices().first(3)
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 7
Source Project: flink   Source File: ScatterGatherConfigurationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration() throws Exception {
	/*
	 * Test Graph's runScatterGatherIteration when configuration parameters are not provided
	 * i.e. degrees and numVertices will be -1, EdgeDirection will be OUT.
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(),
		TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());

	Graph<Long, Long, Long> res = graph.runScatterGatherIteration(
		new MessageFunctionDefault(), new UpdateFunctionDefault(), 5);

	DataSet<Tuple2<Long, Long>> data = res.getVertices().map(new VertexToTuple2Map<>());
	List<Tuple2<Long, Long>> result = data.collect();

	expectedResult = "1,6\n" +
		"2,6\n" +
		"3,6\n" +
		"4,6\n" +
		"5,6";

	compareResultAsTuples(result, expectedResult);
}
 
Example 8
Source Project: flink   Source File: CollectionModeSuperstepITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testProgram() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(),
			TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());

	Graph<Long, Long, Long> result = graph.runScatterGatherIteration(
			new MessageFunction(), new UpdateFunction(), 10);

	result.getVertices().map(
		new VertexToTuple2Map<>()).output(
			new DiscardingOutputFormat<>());

	env.execute();
}
 
Example 9
Source Project: flink   Source File: JoinWithVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithVertexSet() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet parameter identical
	 * to the vertex DataSet
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices()
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,8\n" +
		"5,10\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 10
Source Project: flink   Source File: JoinWithVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLessElements() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet passed as a parameter containing
	 * less elements than the vertex DataSet, but of the same type
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices().first(3)
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 11
Source Project: flink   Source File: ScatterGatherConfigurationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration() throws Exception {
	/*
	 * Test Graph's runScatterGatherIteration when configuration parameters are not provided
	 * i.e. degrees and numVertices will be -1, EdgeDirection will be OUT.
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(),
		TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());

	Graph<Long, Long, Long> res = graph.runScatterGatherIteration(
		new MessageFunctionDefault(), new UpdateFunctionDefault(), 5);

	DataSet<Tuple2<Long, Long>> data = res.getVertices().map(new VertexToTuple2Map<>());
	List<Tuple2<Long, Long>> result = data.collect();

	expectedResult = "1,6\n" +
		"2,6\n" +
		"3,6\n" +
		"4,6\n" +
		"5,6";

	compareResultAsTuples(result, expectedResult);
}
 
Example 12
Source Project: flink   Source File: CollectionModeSuperstepITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testProgram() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(),
			TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());

	Graph<Long, Long, Long> result = graph.runScatterGatherIteration(
			new MessageFunction(), new UpdateFunction(), 10);

	result.getVertices().map(
		new VertexToTuple2Map<>()).output(
			new DiscardingOutputFormat<>());

	env.execute();
}
 
Example 13
Source Project: Flink-CEPplus   Source File: Graph.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return the vertex DataSet as Tuple2.
 */
public DataSet<Tuple2<K, VV>> getVerticesAsTuple2() {
	return vertices.map(new VertexToTuple2Map<>());
}
 
Example 14
Source Project: flink   Source File: Graph.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return the vertex DataSet as Tuple2.
 */
public DataSet<Tuple2<K, VV>> getVerticesAsTuple2() {
	return vertices.map(new VertexToTuple2Map<>());
}
 
Example 15
Source Project: flink   Source File: Graph.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return the vertex DataSet as Tuple2.
 */
public DataSet<Tuple2<K, VV>> getVerticesAsTuple2() {
	return vertices.map(new VertexToTuple2Map<>());
}