Search in sources :

Example 91 with Edge

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

the class GraphMutationsITCase method testRemoveInvalidVertex.

@Test
public void testRemoveInvalidVertex() throws Exception {
    /*
         * Test removeVertex() -- remove an invalid vertex
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
    graph = graph.removeVertex(new Vertex<>(6L, 6L));
    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";
    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 92 with Edge

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

the class SummarizationITCase method testWithVertexAndEdgeLongValues.

@Test
public void testWithVertexAndEdgeLongValues() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> input = Graph.fromDataSet(SummarizationData.getVertices(env), SummarizationData.getEdges(env), env).run(new TranslateVertexValues<>(new StringToLong())).run(new TranslateEdgeValues<>(new StringToLong()));
    List<Vertex<Long, Summarization.VertexValue<Long>>> summarizedVertices = new ArrayList<>();
    List<Edge<Long, EdgeValue<Long>>> summarizedEdges = new ArrayList<>();
    Graph<Long, Summarization.VertexValue<Long>, EdgeValue<Long>> output = input.run(new Summarization<>());
    output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
    output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));
    env.execute();
    validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
    validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) TranslateVertexValues(org.apache.flink.graph.asm.translate.TranslateVertexValues) EdgeValue(org.apache.flink.graph.library.Summarization.EdgeValue) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 93 with Edge

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

the class IncrementalSSSPITCase method testIncrementalSSSPNonSPEdge.

@Test
public void testIncrementalSSSPNonSPEdge() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Vertex<Long, Double>> vertices = IncrementalSSSPData.getDefaultVertexDataSet(env);
    DataSet<Edge<Long, Double>> edges = IncrementalSSSPData.getDefaultEdgeDataSet(env);
    DataSet<Edge<Long, Double>> edgesInSSSP = IncrementalSSSPData.getDefaultEdgesInSSSP(env);
    // the edge to be removed is a non-SP edge
    Edge<Long, Double> edgeToBeRemoved = new Edge<>(3L, 5L, 5.0);
    Graph<Long, Double, Double> graph = Graph.fromDataSet(vertices, edges, env);
    // Assumption: all minimum weight paths are kept
    Graph<Long, Double, Double> ssspGraph = Graph.fromDataSet(vertices, edgesInSSSP, env);
    // remove the edge
    graph.removeEdge(edgeToBeRemoved);
    // configure the iteration
    ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
    if (IncrementalSSSP.isInSSSP(edgeToBeRemoved, edgesInSSSP)) {
        parameters.setDirection(EdgeDirection.IN);
        parameters.setOptDegrees(true);
        // run the scatter gather iteration to propagate info
        Graph<Long, Double, Double> result = ssspGraph.runScatterGatherIteration(new IncrementalSSSP.InvalidateMessenger(edgeToBeRemoved), new IncrementalSSSP.VertexDistanceUpdater(), IncrementalSSSPData.NUM_VERTICES, parameters);
        DataSet<Vertex<Long, Double>> resultedVertices = result.getVertices();
        resultedVertices.writeAsCsv(resultPath, "\n", ",");
        env.execute();
    } else {
        vertices.writeAsCsv(resultPath, "\n", ",");
        env.execute();
    }
    expected = IncrementalSSSPData.VERTICES;
}
Also used : IncrementalSSSP(org.apache.flink.graph.examples.IncrementalSSSP) Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ScatterGatherConfiguration(org.apache.flink.graph.spargel.ScatterGatherConfiguration) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 94 with Edge

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

the class SummarizationITCase method testWithVertexAndEdgeStringValues.

@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, String, String> input = Graph.fromDataSet(SummarizationData.getVertices(env), SummarizationData.getEdges(env), env);
    List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
    List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();
    Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output = input.run(new Summarization<>());
    output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
    output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));
    env.execute();
    validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
    validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) EdgeValue(org.apache.flink.graph.library.Summarization.EdgeValue) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 95 with Edge

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

the class SummarizationITCase method testWithVertexAndAbsentEdgeStringValues.

@Test
public void testWithVertexAndAbsentEdgeStringValues() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, String, NullValue> input = Graph.fromDataSet(SummarizationData.getVertices(env), SummarizationData.getEdges(env), env).run(new TranslateEdgeValues<>(new ToNullValue<>()));
    List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
    List<Edge<Long, EdgeValue<NullValue>>> summarizedEdges = new ArrayList<>();
    Graph<Long, Summarization.VertexValue<String>, EdgeValue<NullValue>> output = input.run(new Summarization<>());
    output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
    output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));
    env.execute();
    validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
    validateEdges(SummarizationData.EXPECTED_EDGES_ABSENT_VALUES, summarizedEdges);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) ToNullValue(org.apache.flink.graph.asm.translate.translators.ToNullValue) NullValue(org.apache.flink.types.NullValue) ToNullValue(org.apache.flink.graph.asm.translate.translators.ToNullValue) EdgeValue(org.apache.flink.graph.library.Summarization.EdgeValue) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.apache.flink.graph.Edge)251 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)210 Test (org.junit.Test)207 Vertex (org.apache.flink.graph.Vertex)132 NullValue (org.apache.flink.types.NullValue)58 LongValue (org.apache.flink.types.LongValue)44 ArrayList (java.util.ArrayList)42 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)34 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)21 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)21 Plan (org.apache.flink.api.common.Plan)18 FieldList (org.apache.flink.api.common.operators.util.FieldList)18 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)18 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)18 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)18 PlanNode (org.apache.flink.optimizer.plan.PlanNode)18 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)18 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)18 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)13 FilterFunction (org.apache.flink.api.common.functions.FilterFunction)12