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);
}
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();
}
}
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);
}
}
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);
}
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);
}
Aggregations