use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class VertexMessageRecvPartitionTest method addTwentyDuplicateVertexBuffer.
private static void addTwentyDuplicateVertexBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
vertex.properties(properties);
ReceiverUtil.consumeBuffer(writeVertex(vertex), consumer);
}
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Properties properties = graphFactory().createProperties();
properties.put("p2", new LongValue(2L * i));
vertex.properties(properties);
ReceiverUtil.consumeBuffer(writeVertex(vertex), consumer);
}
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class WriteBufferTest method testWriteVertex.
@Test
public void testWriteVertex() throws IOException {
GraphFactory graphFactory = context.graphFactory();
// NOTE: need ensure the buffer size can hold follow writed bytes
WriteBuffer buffer = new WriteBuffer(context, 100, 110);
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffer.writeVertex(vertex);
long position1 = buffer.output().position();
Assert.assertGt(0L, position1);
vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
Properties properties = graphFactory.createProperties();
properties.put("name", BytesId.of("marko"));
properties.put("age", new IntValue(18));
properties.put("city", new ListValue<>(ValueType.ID, ImmutableList.of(BytesId.of("wuhan"), BytesId.of("xian"))));
vertex.properties(properties);
buffer.writeVertex(vertex);
long position2 = buffer.output().position();
Assert.assertGt(position1, position2);
vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
buffer.writeEdges(vertex);
long position3 = buffer.output().position();
Assert.assertGt(position2, position3);
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class StreamGraphOutput method writeEdges.
@Override
public void writeEdges(Vertex vertex) throws IOException {
KvEntryWriter writer = this.out.writeEntry(out -> {
// Write id
this.writeId(out, vertex.id());
});
if (this.frequency == EdgeFrequency.SINGLE) {
for (Edge edge : vertex.edges()) {
// Only use targetId as subKey, use properties as subValue
writer.writeSubKv(out -> {
this.writeId(out, edge.targetId());
}, out -> {
this.writeProperties(out, edge.properties());
});
}
} else if (this.frequency == EdgeFrequency.SINGLE_PER_LABEL) {
for (Edge edge : vertex.edges()) {
// Use label + targetId as subKey, use properties as subValue
writer.writeSubKv(out -> {
this.writeLabel(out, edge.label());
this.writeId(out, edge.targetId());
}, out -> {
this.writeProperties(out, edge.properties());
});
}
} else {
assert this.frequency == EdgeFrequency.MULTIPLE;
for (Edge edge : vertex.edges()) {
/*
* Use label + sortValues + targetId as subKey,
* use properties as subValue
*/
writer.writeSubKv(out -> {
this.writeLabel(out, edge.label());
this.writeLabel(out, edge.name());
this.writeId(out, edge.targetId());
}, out -> {
this.writeProperties(out, edge.properties());
});
}
}
writer.writeFinish();
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method addSingleFreqEdgeBuffer.
private static void addSingleFreqEdgeBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 200L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
int count = RANDOM.nextInt(20);
if (count == 0) {
continue;
}
Edges edges = graphFactory().createEdges(count);
for (long j = 0; j < count; j++) {
Edge edge = graphFactory().createEdge();
edge.targetId(BytesId.of(RANDOM.nextInt(200)));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex, EdgeFrequency.SINGLE), consumer);
}
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class EdgesInputTest method addEdgeBuffer.
private static void addEdgeBuffer(Consumer<NetworkBuffer> consumer, EdgeFrequency freq) throws IOException {
for (long i = 0L; i < 200L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
int count = (int) i;
if (count == 0) {
continue;
}
Edges edges = graphFactory().createEdges(count);
for (long j = 0; j < count; j++) {
Edge edge = graphFactory().createEdge();
switch(freq) {
case SINGLE:
edge.targetId(BytesId.of(j));
break;
case SINGLE_PER_LABEL:
edge.label(String.valueOf(j));
edge.targetId(BytesId.of(j));
break;
case MULTIPLE:
edge.name(String.valueOf(j));
edge.label(String.valueOf(j));
edge.targetId(BytesId.of(j));
break;
default:
throw new ComputerException("Illegal edge frequency %s", freq);
}
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex, freq), consumer);
}
}
Aggregations