Java Code Examples for org.apache.flink.graph.Vertex#getId()

The following examples show how to use org.apache.flink.graph.Vertex#getId() . 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 File: Summarization.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Vertex<K, VV>> values, Collector<VertexGroupItem<K, VV>> out) throws Exception {
	K vertexGroupRepresentativeID = null;
	long vertexGroupCount = 0L;
	VV vertexGroupValue = null;
	boolean isFirstElement = true;

	for (Vertex<K, VV> vertex : values) {
		if (isFirstElement) {
			// take final group representative vertex id from first tuple
			vertexGroupRepresentativeID = vertex.getId();
			vertexGroupValue = vertex.getValue();
			isFirstElement = false;
		}
		// no need to set group value for those tuples
		reuseVertexGroupItem.setVertexId(vertex.getId());
		reuseVertexGroupItem.setGroupRepresentativeId(vertexGroupRepresentativeID);
		out.collect(reuseVertexGroupItem);
		vertexGroupCount++;
	}

	createGroupRepresentativeTuple(vertexGroupRepresentativeID, vertexGroupValue, vertexGroupCount);
	out.collect(reuseVertexGroupItem);
	reuseVertexGroupItem.reset();
}
 
Example 2
Source File: Summarization.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Vertex<K, VV>> values, Collector<VertexGroupItem<K, VV>> out) throws Exception {
	K vertexGroupRepresentativeID = null;
	long vertexGroupCount = 0L;
	VV vertexGroupValue = null;
	boolean isFirstElement = true;

	for (Vertex<K, VV> vertex : values) {
		if (isFirstElement) {
			// take final group representative vertex id from first tuple
			vertexGroupRepresentativeID = vertex.getId();
			vertexGroupValue = vertex.getValue();
			isFirstElement = false;
		}
		// no need to set group value for those tuples
		reuseVertexGroupItem.setVertexId(vertex.getId());
		reuseVertexGroupItem.setGroupRepresentativeId(vertexGroupRepresentativeID);
		out.collect(reuseVertexGroupItem);
		vertexGroupCount++;
	}

	createGroupRepresentativeTuple(vertexGroupRepresentativeID, vertexGroupValue, vertexGroupCount);
	out.collect(reuseVertexGroupItem);
	reuseVertexGroupItem.reset();
}
 
Example 3
Source File: Summarization.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Vertex<K, VV>> values, Collector<VertexGroupItem<K, VV>> out) throws Exception {
	K vertexGroupRepresentativeID = null;
	long vertexGroupCount = 0L;
	VV vertexGroupValue = null;
	boolean isFirstElement = true;

	for (Vertex<K, VV> vertex : values) {
		if (isFirstElement) {
			// take final group representative vertex id from first tuple
			vertexGroupRepresentativeID = vertex.getId();
			vertexGroupValue = vertex.getValue();
			isFirstElement = false;
		}
		// no need to set group value for those tuples
		reuseVertexGroupItem.setVertexId(vertex.getId());
		reuseVertexGroupItem.setGroupRepresentativeId(vertexGroupRepresentativeID);
		out.collect(reuseVertexGroupItem);
		vertexGroupCount++;
	}

	createGroupRepresentativeTuple(vertexGroupRepresentativeID, vertexGroupValue, vertexGroupCount);
	out.collect(reuseVertexGroupItem);
	reuseVertexGroupItem.reset();
}
 
Example 4
Source File: ScatterGatherConfigurationITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessages(Vertex<Long, Long> vertex) {
	if (vertex.getId() == 1) {
		Assert.assertEquals(2, getOutDegree());
		Assert.assertEquals(1, getInDegree());
	} else if (vertex.getId() == 3) {
		Assert.assertEquals(2, getOutDegree());
		Assert.assertEquals(2, getInDegree());
	}
	//send message to keep vertices active
	sendMessageToAllNeighbors(vertex.getValue());
}
 
Example 5
Source File: ReduceOnNeighborMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateNeighbors(Vertex<Long, Long> vertex,
		Iterable<Tuple2<Edge<Long, Long>, Vertex<Long, Long>>> neighbors,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	long sum = 0;
	for (Tuple2<Edge<Long, Long>, Vertex<Long, Long>> neighbor : neighbors) {
		sum += neighbor.f1.getValue();
	}
	if (vertex.getId() > 3) {
		out.collect(new Tuple2<>(vertex.getId(), sum));
	}
}
 
Example 6
Source File: ReduceOnNeighborMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateNeighbors(Vertex<Long, Long> vertex,
		Iterable<Tuple2<Edge<Long, Long>, Vertex<Long, Long>>> neighbors,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	long sum = 0;
	for (Tuple2<Edge<Long, Long>, Vertex<Long, Long>> neighbor : neighbors) {
		sum += neighbor.f1.getValue();
	}
	if (vertex.getId() > 3) {
		out.collect(new Tuple2<>(vertex.getId(), sum + vertex.getValue()));
	}
}
 
Example 7
Source File: ReduceOnNeighborMethodsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateNeighbors(Vertex<Long, Long> vertex,
		Iterable<Tuple2<Edge<Long, Long>, Vertex<Long, Long>>> neighbors,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	long sum = 0;
	for (Tuple2<Edge<Long, Long>, Vertex<Long, Long>> neighbor : neighbors) {
		sum += neighbor.f0.getValue() * neighbor.f1.getValue();
	}
	if (vertex.getId() > 3) {
		out.collect(new Tuple2<>(vertex.getId(), sum));
	}
}
 
Example 8
Source File: Projection.java    From flink with Apache License 2.0 5 votes vote down vote up
public Projection(
		Vertex<KC, VVC> connectingVertex,
		VV sourceVertexValue, VV targetVertexValue,
		EV sourceEdgeValue, EV targetEdgeValue) {
	this.f0 = connectingVertex.getId();
	this.f1 = connectingVertex.getValue();
	this.f2 = sourceVertexValue;
	this.f3 = targetVertexValue;
	this.f4 = sourceEdgeValue;
	this.f5 = targetEdgeValue;
}
 
Example 9
Source File: Projection.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public Projection(
		Vertex<KC, VVC> connectingVertex,
		VV sourceVertexValue, VV targetVertexValue,
		EV sourceEdgeValue, EV targetEdgeValue) {
	this.f0 = connectingVertex.getId();
	this.f1 = connectingVertex.getValue();
	this.f2 = sourceVertexValue;
	this.f3 = targetVertexValue;
	this.f4 = sourceEdgeValue;
	this.f5 = targetEdgeValue;
}
 
Example 10
Source File: ReduceOnNeighborMethodsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateNeighbors(Vertex<Long, Long> vertex,
		Iterable<Tuple2<Edge<Long, Long>, Vertex<Long, Long>>> neighbors,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	long sum = 0;
	for (Tuple2<Edge<Long, Long>, Vertex<Long, Long>> neighbor : neighbors) {
		sum += neighbor.f1.getValue();
	}
	if (vertex.getId() > 3) {
		out.collect(new Tuple2<>(vertex.getId(), sum));
	}
}
 
Example 11
Source File: VertexCentricIteration.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<K, Either<NullValue, Message>> map(Vertex<K, VV> vertex) {
	outTuple.f0 = vertex.getId();
	return outTuple;
}
 
Example 12
Source File: TestFilterVertices.java    From gelly-streaming with Apache License 2.0 4 votes vote down vote up
@Override
public boolean filter(Vertex<Long, NullValue> vertex) throws Exception {
    return vertex.getId() > 1;
}
 
Example 13
Source File: VertexCentricIteration.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<K, Either<NullValue, Message>> map(Vertex<K, VV> vertex) {
	outTuple.f0 = vertex.getId();
	return outTuple;
}
 
Example 14
Source File: JoinWithVerticesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Boolean> map(Vertex<Long, Long> vertex) throws Exception {
	return new Tuple2<>(vertex.getId(), true);
}
 
Example 15
Source File: CommunityDetection.java    From flink with Apache License 2.0 4 votes vote down vote up
public Vertex<K, Tuple2<Long, Double>> map(Vertex<K, Long> vertex) {
	return new Vertex<>(vertex.getId(), new Tuple2<>(vertex.getValue(), 1.0));
}
 
Example 16
Source File: JoinWithVerticesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Boolean> map(Vertex<Long, Long> vertex) throws Exception {
	return new Tuple2<>(vertex.getId(), true);
}
 
Example 17
Source File: CommunityDetection.java    From flink with Apache License 2.0 4 votes vote down vote up
public Vertex<K, Tuple2<Long, Double>> map(Vertex<K, Long> vertex) {
	return new Vertex<>(vertex.getId(), new Tuple2<>(vertex.getValue(), 1.0));
}
 
Example 18
Source File: JoinWithVerticesITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Boolean> map(Vertex<Long, Long> vertex) throws Exception {
	return new Tuple2<>(vertex.getId(), true);
}
 
Example 19
Source File: CommunityDetection.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Vertex<K, Tuple2<Long, Double>> map(Vertex<K, Long> vertex) {
	return new Vertex<>(vertex.getId(), new Tuple2<>(vertex.getValue(), 1.0));
}
 
Example 20
Source File: VertexCentricIteration.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Tuple2<K, Either<NullValue, Message>> map(Vertex<K, VV> vertex) {
	outTuple.f0 = vertex.getId();
	return outTuple;
}