Java Code Examples for org.apache.flink.types.NullValue

The following examples show how to use org.apache.flink.types.NullValue. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flink   Source File: CirculantGraphTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphMetrics() throws Exception {
	int vertexCount = 10;
	int offset = 4;
	int length = 2;

	Graph<LongValue, NullValue, NullValue> graph = new CirculantGraph(env, 10)
		.addRange(offset, length)
		.generate();

	assertEquals(vertexCount, graph.numberOfVertices());
	assertEquals(vertexCount * length, graph.numberOfEdges());

	long maxInDegree = graph.inDegrees().max(1).collect().get(0).f1.getValue();
	long maxOutDegree = graph.outDegrees().max(1).collect().get(0).f1.getValue();

	assertEquals(length, maxInDegree);
	assertEquals(length, maxOutDegree);
}
 
Example 2
Source Project: Flink-CEPplus   Source File: VertexDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEmptyGraphWithoutVertices() throws Exception {
	DataSet<Vertex<LongValue, LongValue>> degree;

	degree = emptyGraphWithoutVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degree.collect().size());

	degree = emptyGraphWithoutVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	assertEquals(0, degree.collect().size());
}
 
Example 3
Source Project: Flink-CEPplus   Source File: CycleGraphTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphMetrics() throws Exception {
	int vertexCount = 100;

	Graph<LongValue, NullValue, NullValue> graph = new CycleGraph(env, vertexCount)
		.generate();

	assertEquals(vertexCount, graph.numberOfVertices());
	assertEquals(2 * vertexCount, graph.numberOfEdges());

	long minInDegree = graph.inDegrees().min(1).collect().get(0).f1.getValue();
	long minOutDegree = graph.outDegrees().min(1).collect().get(0).f1.getValue();
	long maxInDegree = graph.inDegrees().max(1).collect().get(0).f1.getValue();
	long maxOutDegree = graph.outDegrees().max(1).collect().get(0).f1.getValue();

	assertEquals(2, minInDegree);
	assertEquals(2, minOutDegree);
	assertEquals(2, maxInDegree);
	assertEquals(2, maxOutDegree);
}
 
Example 4
Source Project: flink   Source File: VertexDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	DataSet<Vertex<LongValue, LongValue>> degree;

	degree = emptyGraphWithVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degree.collect().size());

	degree = emptyGraphWithVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,0)\n" +
		"(1,0)\n" +
		"(2,0)";

	TestBaseUtils.compareResultAsText(degree.collect(), expectedResult);
}
 
Example 5
Source Project: flink   Source File: VertexDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEmptyGraphWithoutVertices() throws Exception {
	DataSet<Vertex<LongValue, LongValue>> degree;

	degree = emptyGraphWithoutVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degree.collect().size());

	degree = emptyGraphWithoutVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	assertEquals(0, degree.collect().size());
}
 
Example 6
Source Project: Flink-CEPplus   Source File: EdgeDegreesPairTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	String expectedResult =
		"(0,1,((null),(2,2,0),(3,0,3)))\n" +
		"(0,2,((null),(2,2,0),(3,2,1)))\n" +
		"(2,1,((null),(3,2,1),(3,0,3)))\n" +
		"(2,3,((null),(3,2,1),(4,2,2)))\n" +
		"(3,1,((null),(4,2,2),(3,0,3)))\n" +
		"(3,4,((null),(4,2,2),(1,0,1)))\n" +
		"(5,3,((null),(1,1,0),(4,2,2)))";

	DataSet<Edge<IntValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = directedSimpleGraph
		.run(new EdgeDegreesPair<>());

	TestBaseUtils.compareResultAsText(degreesPair.collect(), expectedResult);
}
 
Example 7
Source Project: Flink-CEPplus   Source File: VertexInDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDirectedSimpleGraph() throws Exception {
	DataSet<Vertex<IntValue, LongValue>> inDegree = directedSimpleGraph
		.run(new VertexInDegree<IntValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,0)\n" +
		"(1,3)\n" +
		"(2,1)\n" +
		"(3,2)\n" +
		"(4,1)\n" +
		"(5,0)";

	TestBaseUtils.compareResultAsText(inDegree.collect(), expectedResult);
}
 
Example 8
@Override
protected void testProgram() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Long> vertexIds = env.generateSequence(1, NUM_VERTICES);
	DataSet<String> edgeString = env.fromElements(ConnectedComponentsData.getRandomOddEvenEdges(NUM_EDGES, NUM_VERTICES, SEED).split("\n"));

	DataSet<Edge<Long, NullValue>> edges = edgeString.map(new EdgeParser());

	DataSet<Vertex<Long, Long>> initialVertices = vertexIds.map(new IdAssigner());

	Graph<Long, Long, NullValue> graph = Graph.fromDataSet(initialVertices, edges, env);

	DataSet<Vertex<Long, Long>> result = graph.run(new ConnectedComponents<>(100));

	result.writeAsCsv(resultPath, "\n", " ");
	env.execute();
}
 
Example 9
Source Project: Flink-CEPplus   Source File: GSAConnectedComponents.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception {

	// get type information for vertex value
	TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1);

	Graph<K, VV, NullValue> undirectedGraph = graph
		.mapEdges(new MapTo<>(NullValue.getInstance()))
		.getUndirected();

	return undirectedGraph.runGatherSumApplyIteration(
		new GatherNeighborIds<>(valueTypeInfo),
		new SelectMinId<>(valueTypeInfo),
		new UpdateComponentId<>(valueTypeInfo),
		maxIterations).getVertices();
}
 
Example 10
Source Project: flink   Source File: SimplifyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setup() throws Exception{
	super.setup();

	Object[][] edges = new Object[][]{
		new Object[]{0, 0},
		new Object[]{0, 1},
		new Object[]{0, 1},
		new Object[]{0, 2},
		new Object[]{0, 2},
		new Object[]{1, 0},
		new Object[]{2, 2},
	};

	List<Edge<IntValue, NullValue>> edgeList = new LinkedList<>();

	for (Object[] edge : edges) {
		edgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance()));
	}

	graph = Graph.fromCollection(edgeList, env);
}
 
Example 11
Source Project: flink   Source File: JaccardIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSimpleGraphWithMaximumScore() throws Exception {
	DataSet<Result<IntValue>> ji = undirectedSimpleGraph
		.run(new JaccardIndex<IntValue, NullValue, NullValue>()
			.setMaximumScore(1, 2));

	String expectedResult =
		"(0,1,1,4)\n" +
		"(0,2,1,4)\n" +
		"(0,3,2,4)\n" +
		"(1,2,2,4)\n" +
		"(1,3,1,6)\n" +
		"(1,4,1,3)\n" +
		"(1,5,1,3)\n" +
		"(2,3,1,6)\n" +
		"(2,4,1,3)\n" +
		"(2,5,1,3)\n";

	TestBaseUtils.compareResultAsText(ji.collect(), expectedResult);
}
 
Example 12
Source Project: gelly-streaming   Source File: TestMapEdges.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithTupleType() throws Exception {
	/*
	 * Test mapEdges() converting the edge value type to tuple
     */
       final String resultPath = getTempDirPath("result");
       final String expectedResult = "1,2,(12,13)\n" +
               "1,3,(13,14)\n" +
               "2,3,(23,24)\n" +
               "3,4,(34,35)\n" +
               "3,5,(35,36)\n" +
               "4,5,(45,46)\n" +
               "5,1,(51,52)\n";
	final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	GraphStream<Long, NullValue, Long> graph = new SimpleEdgeStream<>(GraphStreamTestUtils.getLongLongEdgeDataStream(env), env);
       graph.mapEdges(new ToTuple2Mapper())
               .getEdges()
               .writeAsCsv(resultPath, FileSystem.WriteMode.OVERWRITE);
	env.execute();
       compareResultsByLinesInMemory(expectedResult, resultPath);
   }
 
Example 13
Source Project: flink   Source File: GraphCreationWithCsvITCase.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 14
Source Project: Flink-CEPplus   Source File: EdgeTargetDegreesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	String expectedResult =
		"(0,1,((null),(3,0,3)))\n" +
		"(0,2,((null),(3,2,1)))\n" +
		"(2,1,((null),(3,0,3)))\n" +
		"(2,3,((null),(4,2,2)))\n" +
		"(3,1,((null),(3,0,3)))\n" +
		"(3,4,((null),(1,0,1)))\n" +
		"(5,3,((null),(4,2,2)))";

	DataSet<Edge<IntValue, Tuple2<NullValue, Degrees>>> targetDegrees = directedSimpleGraph
			.run(new EdgeTargetDegrees<>());

	TestBaseUtils.compareResultAsText(targetDegrees.collect(), expectedResult);
}
 
Example 15
Source Project: flink   Source File: ValueArrayFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Produce a {@code ValueArray} for the given {@code Value} type.
 *
 * @param cls {@code Value} class
 * @return {@code ValueArray} for given {@code Value} class
 */
@SuppressWarnings("unchecked")
public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls) {
	if (ByteValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new ByteValueArray();
	} else if (CharValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new CharValueArray();
	} else if (DoubleValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new DoubleValueArray();
	} else if (FloatValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new FloatValueArray();
	} else if (IntValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new IntValueArray();
	} else if (LongValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new LongValueArray();
	} else if (NullValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new NullValueArray();
	} else if (ShortValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new ShortValueArray();
	} else if (StringValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new StringValueArray();
	} else {
		throw new IllegalArgumentException("Unable to create unbounded ValueArray for type " + cls);
	}
}
 
Example 16
Source Project: Flink-CEPplus   Source File: VertexOutDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDirectedSimpleGraph() throws Exception {
	DataSet<Vertex<IntValue, LongValue>> outDegree = directedSimpleGraph
		.run(new VertexOutDegree<IntValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,2)\n" +
		"(1,0)\n" +
		"(2,2)\n" +
		"(3,2)\n" +
		"(4,0)\n" +
		"(5,1)";

	TestBaseUtils.compareResultAsText(outDegree.collect(), expectedResult);
}
 
Example 17
Source Project: Flink-CEPplus   Source File: VertexInDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithUndirectedSimpleGraph() throws Exception {
	DataSet<Vertex<IntValue, LongValue>> inDegree = undirectedSimpleGraph
		.run(new VertexInDegree<IntValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,2)\n" +
		"(1,3)\n" +
		"(2,3)\n" +
		"(3,4)\n" +
		"(4,1)\n" +
		"(5,1)";

	TestBaseUtils.compareResultAsText(inDegree.collect(), expectedResult);
}
 
Example 18
Source Project: flink   Source File: SingletonEdgeGraphTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphMetrics() throws Exception {
	int vertexPairCount = 10;

	Graph<LongValue, NullValue, NullValue> graph = new SingletonEdgeGraph(env, vertexPairCount)
		.generate();

	assertEquals(2 * vertexPairCount, graph.numberOfVertices());
	assertEquals(2 * vertexPairCount, graph.numberOfEdges());

	long minInDegree = graph.inDegrees().min(1).collect().get(0).f1.getValue();
	long minOutDegree = graph.outDegrees().min(1).collect().get(0).f1.getValue();
	long maxInDegree = graph.inDegrees().max(1).collect().get(0).f1.getValue();
	long maxOutDegree = graph.outDegrees().max(1).collect().get(0).f1.getValue();

	assertEquals(1, minInDegree);
	assertEquals(1, minOutDegree);
	assertEquals(1, maxInDegree);
	assertEquals(1, maxOutDegree);
}
 
Example 19
Source Project: Flink-CEPplus   Source File: EdgeDegreesPairTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	DataSet<Edge<LongValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = emptyGraphWithVertices
		.run(new EdgeDegreesPair<>());

	assertEquals(0, degreesPair.collect().size());
}
 
Example 20
Source Project: Flink-CEPplus   Source File: EdgeSourceDegreesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	DataSet<Edge<LongValue, Tuple2<NullValue, Degrees>>> sourceDegrees = directedRMatGraph(10, 16)
		.run(new EdgeSourceDegrees<>());

	Checksum checksum = new ChecksumHashCode<Edge<LongValue, Tuple2<NullValue, Degrees>>>()
		.run(sourceDegrees)
		.execute();

	assertEquals(12009, checksum.getCount());
	assertEquals(0x0000162435fde1d9L, checksum.getChecksum());
}
 
Example 21
Source Project: Flink-CEPplus   Source File: SingletonEdgeGraphTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGraph() throws Exception {
	int vertexPairCount = 5;

	Graph<LongValue, NullValue, NullValue> graph = new SingletonEdgeGraph(env, vertexPairCount)
		.generate();

	String vertices = "0; 1; 2; 3; 4; 5; 6; 7; 8; 9";
	String edges = "0,1; 1,0; 2,3; 3,2; 4,5; 5,4; 6,7; 7,6; 8,9; 9,8";

	TestUtils.compareGraph(graph, vertices, edges);
}
 
Example 22
Source Project: flink   Source File: EdgeTargetDegreeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	DataSet<Edge<LongValue, Tuple2<NullValue, LongValue>>> targetDegreeOnTargetId = emptyGraphWithVertices
		.run(new EdgeTargetDegree<LongValue, NullValue, NullValue>()
			.setReduceOnSourceId(false));

	assertEquals(0, targetDegreeOnTargetId.collect().size());

	DataSet<Edge<LongValue, Tuple2<NullValue, LongValue>>> targetDegreeOnSourceId = emptyGraphWithVertices
		.run(new EdgeTargetDegree<LongValue, NullValue, NullValue>()
			.setReduceOnSourceId(true));

	assertEquals(0, targetDegreeOnSourceId.collect().size());
}
 
Example 23
Source Project: flink   Source File: MusicProfiles.java    License: Apache License 2.0 5 votes vote down vote up
public void iterateEdges(Vertex<String, NullValue> vertex,
		Iterable<Edge<String, Integer>> edges, Collector<Tuple2<String, String>> out) throws Exception {

	int maxPlaycount = 0;
	String topSong = "";
	for (Edge<String, Integer> edge : edges) {
		if (edge.getValue() > maxPlaycount) {
			maxPlaycount = edge.getValue();
			topSong = edge.getTarget();
		}
	}
	out.collect(new Tuple2<>(vertex.getId(), topSong));
}
 
Example 24
Source Project: flink   Source File: HypercubeGraph.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Graph<LongValue, NullValue, NullValue> generate() {
	Preconditions.checkState(dimensions > 0);

	GridGraph graph = new GridGraph(env);

	for (int i = 0; i < dimensions; i++) {
		graph.addDimension(2, false);
	}

	return graph
		.setParallelism(parallelism)
		.generate();
}
 
Example 25
Source Project: Flink-CEPplus   Source File: ConnectedComponents.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception {

	// get type information for vertex value
	TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1);

	Graph<K, VV, NullValue> undirectedGraph = graph
		.mapEdges(new MapTo<>(NullValue.getInstance()))
		.getUndirected();

	return undirectedGraph.runScatterGatherIteration(
		new CCMessenger<>(valueTypeInfo),
		new CCUpdater<>(),
		maxIterations).getVertices();
}
 
Example 26
Source Project: Flink-CEPplus   Source File: VertexMetricsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param includeZeroDegreeVertices whether to include zero-degree vertices
 * @param result expected {@link Result}
 * @param averageDegree result average degree
 * @param density result density
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T>> void validate(
		Graph<T, NullValue, NullValue> graph, boolean includeZeroDegreeVertices,
		Result result, float averageDegree, float density) throws Exception {
	Result vertexMetrics = new VertexMetrics<T, NullValue, NullValue>()
		.setIncludeZeroDegreeVertices(includeZeroDegreeVertices)
		.run(graph)
		.execute();

	assertEquals(result, vertexMetrics);
	assertEquals(averageDegree, vertexMetrics.getAverageDegree(), ACCURACY);
	assertEquals(density, vertexMetrics.getDensity(), ACCURACY);
}
 
Example 27
Source Project: flink   Source File: CirculantGraphTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGraph() throws Exception {
	Graph<LongValue, NullValue, NullValue> graph = new CirculantGraph(env, 10)
		.addRange(4, 3)
		.generate();

	String vertices = "0; 1; 2; 3; 4; 5; 6; 7; 8; 9";
	String edges = "0,4; 0,5; 0,6; 1,5; 1,6; 1,7; 2,6;" +
		"2,7; 2,8; 3,7; 3,8; 3,9; 4,0; 4,8; 4,9;" +
		"5,0; 5,1; 5,9; 6,0; 6,1; 6,2; 7,1; 7,2; 7,3;" +
		"8,2; 8,3; 8,4; 9,3; 9,4; 9,5";

	TestUtils.compareGraph(graph, vertices, edges);
}
 
Example 28
Source Project: flink   Source File: EchoGraphTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelism() throws Exception {
	int parallelism = 2;

	Graph<LongValue, NullValue, NullValue> graph = new EchoGraph(env, 10, 3)
		.setParallelism(parallelism)
		.generate();

	graph.getVertices().output(new DiscardingOutputFormat<>());
	graph.getEdges().output(new DiscardingOutputFormat<>());

	TestUtils.verifyParallelism(env, parallelism);
}
 
Example 29
Source Project: flink   Source File: ConnectedComponents.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception {

	// get type information for vertex value
	TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1);

	Graph<K, VV, NullValue> undirectedGraph = graph
		.mapEdges(new MapTo<>(NullValue.getInstance()))
		.getUndirected();

	return undirectedGraph.runScatterGatherIteration(
		new CCMessenger<>(valueTypeInfo),
		new CCUpdater<>(),
		maxIterations).getVertices();
}
 
Example 30
Source Project: flink   Source File: TriangleListingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleGraphSorted() throws Exception {
	DataSet<Result<IntValue>> tl = directedSimpleGraph
		.run(new TriangleListing<IntValue, NullValue, NullValue>()
			.setSortTriangleVertices(true));

	String expectedResult =
		"(0,1,2,41)\n" +
		"(1,2,3,22)";

	TestBaseUtils.compareResultAsText(tl.collect(), expectedResult);
}