Search in sources :

Example 1 with NullValue

use of org.apache.flink.types.NullValue in project flink by apache.

the class GraphOperationsITCase method testIntersect.

@Test
public final void testIntersect() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>();
    edges1.add(new Edge<>(1L, 3L, 12L));
    // needs to be in the output
    edges1.add(new Edge<>(1L, 3L, 13L));
    edges1.add(new Edge<>(1L, 3L, 14L));
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>();
    edges2.add(new Edge<>(1L, 3L, 13L));
    Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env);
    Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env);
    Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true);
    List<Vertex<Long, NullValue>> vertices = new ArrayList<>();
    List<Edge<Long, Long>> edges = new ArrayList<>();
    intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices));
    intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges));
    env.execute();
    String expectedVertices = "1,(null)\n" + "3,(null)\n";
    String expectedEdges = "1,3,13\n";
    compareResultAsTuples(vertices, expectedVertices);
    compareResultAsTuples(edges, expectedEdges);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) NullValue(org.apache.flink.types.NullValue) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 2 with NullValue

use of org.apache.flink.types.NullValue in project flink by apache.

the class ConnectedComponents method main.

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
    if (!parseParameters(args)) {
        return;
    }
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Edge<Long, NullValue>> edges = getEdgesDataSet(env);
    Graph<Long, Long, NullValue> graph = Graph.fromDataSet(edges, new MapFunction<Long, Long>() {

        @Override
        public Long map(Long value) throws Exception {
            return value;
        }
    }, env);
    DataSet<Vertex<Long, Long>> verticesWithMinIds = graph.run(new GSAConnectedComponents<Long, Long, NullValue>(maxIterations));
    // emit result
    if (fileOutput) {
        verticesWithMinIds.writeAsCsv(outputPath, "\n", ",");
        // since file sinks are lazy, we trigger the execution explicitly
        env.execute("Connected Components Example");
    } else {
        verticesWithMinIds.print();
    }
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) Edge(org.apache.flink.graph.Edge)

Example 3 with NullValue

use of org.apache.flink.types.NullValue in project flink by apache.

the class TriangleEnumeratorITCase method testTriangleEnumerator.

@Test
public void testTriangleEnumerator() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, NullValue, NullValue> graph = Graph.fromDataSet(TriangleCountData.getDefaultEdgeDataSet(env), env);
    List<Tuple3<Long, Long, Long>> actualOutput = graph.run(new TriangleEnumerator<Long, NullValue, NullValue>()).collect();
    List<Tuple3<Long, Long, Long>> expectedResult = TriangleCountData.getListOfTriangles();
    Assert.assertEquals(expectedResult.size(), actualOutput.size());
    for (Tuple3<Long, Long, Long> resultTriangle : actualOutput) {
        Assert.assertTrue(expectedResult.indexOf(resultTriangle) >= 0);
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Example 4 with NullValue

use of org.apache.flink.types.NullValue in project flink by apache.

the class GatherSumApplyITCase method testConnectedComponentsWithObjectReuseEnabled.

@Test
public void testConnectedComponentsWithObjectReuseEnabled() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().enableObjectReuse();
    DataSet<Edge<LongValue, NullValue>> edges = Translate.translateEdgeIds(ConnectedComponentsDefaultData.getDefaultEdgeDataSet(env), new LongToLongValue());
    Graph<LongValue, LongValue, NullValue> inputGraph = Graph.fromDataSet(edges, new IdentityMapper<LongValue>(), env);
    List<Vertex<LongValue, LongValue>> result = inputGraph.run(new GSAConnectedComponents<LongValue, LongValue, NullValue>(16)).collect();
    compareResultAsTuples(result, expectedResultCC);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) LongToLongValue(org.apache.flink.graph.asm.translate.translators.LongToLongValue) LongValue(org.apache.flink.types.LongValue) LongToLongValue(org.apache.flink.graph.asm.translate.translators.LongToLongValue) GSAConnectedComponents(org.apache.flink.graph.library.GSAConnectedComponents) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 5 with NullValue

use of org.apache.flink.types.NullValue in project flink by apache.

the class LabelPropagationITCase method testTieBreaker.

@Test
public void testTieBreaker() throws Exception {
    /*
		 * Test the label propagation example where a tie must be broken
		 */
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, NullValue> inputGraph = Graph.fromDataSet(LabelPropagationData.getTieVertexSet(env), LabelPropagationData.getTieEdgeDataSet(env), env);
    List<Vertex<Long, Long>> result = inputGraph.run(new LabelPropagation<Long, Long, NullValue>(1)).collect();
    expectedResult = LabelPropagationData.LABELS_WITH_TIE;
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) Test(org.junit.Test)

Aggregations

NullValue (org.apache.flink.types.NullValue)49 Test (org.junit.Test)39 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)33 LongValue (org.apache.flink.types.LongValue)23 Edge (org.apache.flink.graph.Edge)18 Vertex (org.apache.flink.graph.Vertex)18 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)15 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)13 Graph (org.apache.flink.graph.Graph)12 DataSet (org.apache.flink.api.java.DataSet)11 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)11 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)7 JDKRandomGeneratorFactory (org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory)7 NumberFormat (java.text.NumberFormat)6 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)6 Plan (org.apache.flink.api.common.Plan)6 MapFunction (org.apache.flink.api.common.functions.MapFunction)6 FieldList (org.apache.flink.api.common.operators.util.FieldList)6 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)6 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)6