Search in sources :

Example 56 with Edge

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

the class GraphCreationITCase method testValidate.

@Test
public void testValidate() throws Exception {
    /*
		 * Test validate():
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Vertex<Long, Long>> vertices = TestGraphUtils.getLongLongVertexData(env);
    DataSet<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdgeData(env);
    Graph<Long, Long, Long> graph = Graph.fromDataSet(vertices, edges, env);
    Boolean valid = graph.validate(new InvalidVertexIdsValidator<Long, Long, Long>());
    //env.fromElements(result).writeAsText(resultPath);
    //env.fromElements(valid);
    String res = valid.toString();
    List<String> result = new LinkedList<>();
    result.add(res);
    expectedResult = "true";
    compareResultAsText(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 57 with Edge

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

the class GraphCreationITCase method testValidateWithInvalidIds.

@Test
public void testValidateWithInvalidIds() throws Exception {
    /*
		 * Test validate() - invalid vertex ids
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Vertex<Long, Long>> vertices = TestGraphUtils.getLongLongInvalidVertexData(env);
    DataSet<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdgeData(env);
    Graph<Long, Long, Long> graph = Graph.fromDataSet(vertices, edges, env);
    Boolean valid = graph.validate(new InvalidVertexIdsValidator<Long, Long, Long>());
    //env.fromElements(valid);
    String res = valid.toString();
    List<String> result = new LinkedList<>();
    result.add(res);
    expectedResult = "false\n";
    compareResultAsText(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 58 with Edge

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

the class JoinWithEdgesITCase method testOnTargetWithCustom.

@Test
public void testOnTargetWithCustom() throws Exception {
    /*
	     * Test joinWithEdgesOnTarget with a DataSet containing custom parametrised type input values
		 */
    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(TestGraphUtils.getLongCustomTuple2TargetData(env), new CustomValueMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,10\n" + "1,3,20\n" + "2,3,20\n" + "3,4,40\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 59 with Edge

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

the class JoinWithEdgesITCase method testWithEdgesOnTarget.

@Test
public void testWithEdgesOnTarget() throws Exception {
    /*
		 * Test joinWithEdgesOnTarget with the input DataSet parameter identical
		 * to the edge 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.joinWithEdgesOnTarget(graph.getEdges().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,68\n" + "3,5,70\n" + "4,5,80\n" + "5,1,102\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 60 with Edge

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

the class JoinWithEdgesITCase method testOnTargetWithNoCommonKeys.

@Test
public void testOnTargetWithNoCommonKeys() throws Exception {
    /*
		 * Test joinWithEdgesOnTarget with the input DataSet containing different keys than the edge DataSet
		 * - the iterator becomes empty.
		 */
    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(TestGraphUtils.getLongLongTuple2TargetData(env), new DoubleValueMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,20\n" + "1,3,40\n" + "2,3,40\n" + "3,4,80\n" + "3,5,35\n" + "4,5,45\n" + "5,1,140\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