Search in sources :

Example 61 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class JoinWithEdgesITCase method testOnSourceWithLessElements.

@Test
public void testOnSourceWithLessElements() throws Exception {
    /*
		 * Test joinWithEdgesOnSource with the input DataSet passed as a parameter containing
		 * less elements than the edge 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.joinWithEdgesOnSource(graph.getEdges().first(3).map(new ProjectSourceAndValueMapper()), new AddValuesMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,24\n" + "1,3,25\n" + "2,3,46\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 62 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class JoinWithEdgesITCase method testWithOnTargetWithLessElements.

@Test
public void testWithOnTargetWithLessElements() throws Exception {
    /*
		 * Test joinWithEdgesOnTarget with the input DataSet passed as a parameter containing
		 * less elements than the edge 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.joinWithEdgesOnTarget(graph.getEdges().first(3).map(new ProjectTargetAndValueMapper()), new AddValuesMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,24\n" + "1,3,26\n" + "2,3,36\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 63 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class MapEdgesITCase method testWithParametrizedCustomType.

@Test
public void testWithParametrizedCustomType() throws Exception {
    /*
		 * Test mapEdges() and change the value type to a parameterized custom type
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Edge<Long, DummyCustomParameterizedType<Double>>> mappedEdges = graph.mapEdges(new ToCustomParametrizedTypeMapper()).getEdges();
    List<Edge<Long, DummyCustomParameterizedType<Double>>> result = mappedEdges.collect();
    expectedResult = "1,2,(12.0,12)\n" + "1,3,(13.0,13)\n" + "2,3,(23.0,23)\n" + "3,4,(34.0,34)\n" + "3,5,(35.0,35)\n" + "4,5,(45.0,45)\n" + "5,1,(51.0,51)\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 64 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class MapEdgesITCase method testWithTuple1Type.

@Test
public void testWithTuple1Type() throws Exception {
    /*
		 * Test mapEdges() and change the value type to a Tuple1
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Edge<Long, Tuple1<Long>>> mappedEdges = graph.mapEdges(new ToTuple1Mapper()).getEdges();
    List<Edge<Long, Tuple1<Long>>> result = mappedEdges.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";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 65 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class MapEdgesITCase method testWithCustomType.

@Test
public void testWithCustomType() throws Exception {
    /*
		 * Test mapEdges() and change the value type to a custom type
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    DataSet<Edge<Long, DummyCustomType>> mappedEdges = graph.mapEdges(new ToCustomTypeMapper()).getEdges();
    List<Edge<Long, DummyCustomType>> result = mappedEdges.collect();
    expectedResult = "1,2,(T,12)\n" + "1,3,(T,13)\n" + "2,3,(T,23)\n" + "3,4,(T,34)\n" + "3,5,(T,35)\n" + "4,5,(T,45)\n" + "5,1,(T,51)\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.apache.flink.graph.Edge)82 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)70 Test (org.junit.Test)66 Vertex (org.apache.flink.graph.Vertex)39 NullValue (org.apache.flink.types.NullValue)18 ArrayList (java.util.ArrayList)14 LongValue (org.apache.flink.types.LongValue)13 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)11 MapFunction (org.apache.flink.api.common.functions.MapFunction)6 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)6 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)6 LinkedList (java.util.LinkedList)5 Plan (org.apache.flink.api.common.Plan)5 FieldList (org.apache.flink.api.common.operators.util.FieldList)5 DataSet (org.apache.flink.api.java.DataSet)5 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)5 Graph (org.apache.flink.graph.Graph)5 Tuple2ToVertexMap (org.apache.flink.graph.utils.Tuple2ToVertexMap)5 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)5 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)5