Search in sources :

Example 36 with Edge

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

the class GraphMutationsITCase method testAddEdge.

@Test
public void testAddEdge() throws Exception {
    /*
         * Test addEdge() -- simple case
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    graph = graph.addEdge(new Vertex<>(6L, 6L), new Vertex<>(1L, 1L), 61L);
    DataSet<Edge<Long, Long>> data = graph.getEdges();
    List<Edge<Long, Long>> result = data.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" + "6,1,61\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 37 with Edge

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

the class JoinWithEdgesITCase method testOnSourceWithNoCommonKeys.

@Test
public void testOnSourceWithNoCommonKeys() throws Exception {
    /*
         * Test joinWithEdgesOnSource 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.joinWithEdgesOnSource(TestGraphUtils.getLongLongTuple2SourceData(env), new DoubleValueMapper());
    DataSet<Edge<Long, Long>> data = res.getEdges();
    List<Edge<Long, Long>> result = data.collect();
    expectedResult = "1,2,20\n" + "1,3,20\n" + "2,3,60\n" + "3,4,80\n" + "3,5,80\n" + "4,5,120\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 38 with Edge

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

the class JoinWithEdgesITCase method testOnTargetWithDifferentType.

@Test
public void testOnTargetWithDifferentType() throws Exception {
    /*
         * Test joinWithEdgesOnTarget with the input DataSet passed as a parameter containing
         * less elements than the edge DataSet and of a different type(Boolean)
         */
    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 ProjectTargetWithTrueMapper()), new DoubleIfTrueMapper());
    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,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 39 with Edge

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

the class JoinWithEdgesITCase method testWithLessElementsDifferentType.

@Test
public void testWithLessElementsDifferentType() throws Exception {
    /*
         * Test joinWithEdges with the input DataSet passed as a parameter containing
         * less elements than the edge DataSet and of a different type(Boolean)
         */
    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.joinWithEdges(graph.getEdges().first(3).map(new BooleanEdgeValueMapper()), new DoubleIfTrueMapper());
    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,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 40 with Edge

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

the class JoinWithEdgesITCase method testOnSourceWithDifferentType.

@Test
public void testOnSourceWithDifferentType() throws Exception {
    /*
         * Test joinWithEdgesOnSource with the input DataSet passed as a parameter containing
         * less elements than the edge DataSet and of a different type(Boolean)
         */
    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 ProjectSourceWithTrueMapper()), new DoubleIfTrueMapper());
    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,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)

Aggregations

Edge (org.apache.flink.graph.Edge)87 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)72 Test (org.junit.Test)69 Vertex (org.apache.flink.graph.Vertex)46 NullValue (org.apache.flink.types.NullValue)20 LongValue (org.apache.flink.types.LongValue)16 ArrayList (java.util.ArrayList)14 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)12 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)7 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)7 Plan (org.apache.flink.api.common.Plan)6 FieldList (org.apache.flink.api.common.operators.util.FieldList)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)6 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)6 PlanNode (org.apache.flink.optimizer.plan.PlanNode)6 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)6 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)6 LinkedList (java.util.LinkedList)5 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)5