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

The following examples show how to use org.apache.flink.graph.utils.VertexToTuple2Map. 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: JoinWithVerticesITCase.java    From Flink-CEPplus with 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 File: JoinWithVerticesITCase.java    From Flink-CEPplus with 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
Source File: ScatterGatherConfigurationITCase.java    From Flink-CEPplus with 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 #4
Source File: CollectionModeSuperstepITCase.java    From Flink-CEPplus with 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 #5
Source File: JoinWithVerticesITCase.java    From flink with 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 File: JoinWithVerticesITCase.java    From flink with 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 File: ScatterGatherConfigurationITCase.java    From flink with 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 File: CollectionModeSuperstepITCase.java    From flink with 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 File: JoinWithVerticesITCase.java    From flink with 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 File: JoinWithVerticesITCase.java    From flink with 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 File: ScatterGatherConfigurationITCase.java    From flink with 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 File: CollectionModeSuperstepITCase.java    From flink with 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 File: Graph.java    From Flink-CEPplus with 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 File: Graph.java    From flink with 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 File: Graph.java    From flink with 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<>());
}