Search in sources :

Example 46 with NullValue

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

the class GraphCreationWithCsvITCase method testCreateWithOnlyEdgesCsvFile.

@Test
public void testCreateWithOnlyEdgesCsvFile() throws Exception {
    /*
		 * Test with one Csv file one with Edges data. Also tests the configuration method ignoreFistLineEdges()
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    final String fileContent2 = "header\n1,2,ot\n" + "3,2,tt\n" + "3,1,to\n";
    final FileInputSplit split2 = createTempFile(fileContent2);
    Graph<Long, NullValue, String> graph = Graph.fromCsvReader(split2.getPath().toString(), env).ignoreFirstLineEdges().ignoreCommentsVertices("hi").edgeTypes(Long.class, String.class);
    List<Triplet<Long, NullValue, String>> result = graph.getTriplets().collect();
    expectedResult = "1,2,(null),(null),ot\n" + "3,2,(null),(null),tt\n" + "3,1,(null),(null),to\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : FileInputSplit(org.apache.flink.core.fs.FileInputSplit) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) Triplet(org.apache.flink.graph.Triplet) Test(org.junit.Test)

Example 47 with NullValue

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

the class GraphCreationWithCsvITCase method testCsvWithNullEdge.

@Test
public void testCsvWithNullEdge() throws Exception {
    /*
		Test fromCsvReader with edge and vertex path and nullvalue for edge
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    final String vertexFileContent = "1,one\n" + "2,two\n" + "3,three\n";
    final String edgeFileContent = "1,2\n" + "3,2\n" + "3,1\n";
    final FileInputSplit split = createTempFile(vertexFileContent);
    final FileInputSplit edgeSplit = createTempFile(edgeFileContent);
    Graph<Long, String, NullValue> graph = Graph.fromCsvReader(split.getPath().toString(), edgeSplit.getPath().toString(), env).vertexTypes(Long.class, String.class);
    List<Triplet<Long, String, NullValue>> result = graph.getTriplets().collect();
    expectedResult = "1,2,one,two,(null)\n" + "3,2,three,two,(null)\n" + "3,1,three,one,(null)\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : FileInputSplit(org.apache.flink.core.fs.FileInputSplit) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) Triplet(org.apache.flink.graph.Triplet) Test(org.junit.Test)

Example 48 with NullValue

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

the class GraphOperationsITCase method testIntersectWithPairs.

@Test
public final void testIntersectWithPairs() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges1 = new ArrayList<>();
    edges1.add(new Edge<>(1L, 3L, 12L));
    edges1.add(new Edge<>(1L, 3L, 13L));
    // output
    edges1.add(new Edge<>(1L, 3L, 13L));
    // output
    edges1.add(new Edge<>(1L, 3L, 13L));
    // output
    edges1.add(new Edge<>(1L, 3L, 14L));
    @SuppressWarnings("unchecked") List<Edge<Long, Long>> edges2 = new ArrayList<>();
    // output
    edges2.add(new Edge<>(1L, 3L, 13L));
    // output
    edges2.add(new Edge<>(1L, 3L, 13L));
    // output
    edges2.add(new Edge<>(1L, 3L, 14L));
    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, false);
    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" + "1,3,13\n" + "1,3,13\n" + "1,3,13\n" + "1,3,14\n" + "1,3,14";
    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 49 with NullValue

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

the class CoGroupGroupSortITCase method testProgram.

@Override
protected void testProgram() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple2<Long, Long>> input1 = env.fromElements(new Tuple2<Long, Long>(0L, 5L), new Tuple2<Long, Long>(0L, 4L), new Tuple2<Long, Long>(0L, 3L), new Tuple2<Long, Long>(0L, 2L), new Tuple2<Long, Long>(0L, 1L), new Tuple2<Long, Long>(1L, 10L), new Tuple2<Long, Long>(1L, 8L), new Tuple2<Long, Long>(1L, 9L), new Tuple2<Long, Long>(1L, 7L));
    DataSet<TestPojo> input2 = env.fromElements(new TestPojo(0L, 10L, 3L), new TestPojo(0L, 8L, 3L), new TestPojo(0L, 10L, 1L), new TestPojo(0L, 9L, 0L), new TestPojo(0L, 8L, 2L), new TestPojo(0L, 8L, 4L), new TestPojo(1L, 10L, 3L), new TestPojo(1L, 8L, 3L), new TestPojo(1L, 10L, 1L), new TestPojo(1L, 9L, 0L), new TestPojo(1L, 8L, 2L), new TestPojo(1L, 8L, 4L));
    input1.coGroup(input2).where(1).equalTo("b").sortFirstGroup(0, Order.DESCENDING).sortSecondGroup("c", Order.ASCENDING).sortSecondGroup("a", Order.DESCENDING).with(new ValidatingCoGroup()).output(new DiscardingOutputFormat<NullValue>());
    env.execute();
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) Tuple2(org.apache.flink.api.java.tuple.Tuple2)

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