use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class DefaultEdgeTest method testEquals.
@Test
public void testEquals() {
DefaultEdge edge1 = new DefaultEdge(graphFactory());
edge1.label("knows");
edge1.name("2021-06-01");
edge1.targetId(BytesId.of(1L));
Properties properties = new DefaultProperties(graphFactory());
properties.put("p1", new LongValue(1L));
properties.put("p2", new DoubleValue(2.0D));
edge1.properties(properties);
DefaultEdge edge2 = new DefaultEdge(graphFactory(), "knows", "2021-06-01", BytesId.of(1L));
edge2.properties().put("p1", new LongValue(1L));
edge2.properties().put("p2", new DoubleValue(2.0D));
Assert.assertEquals(edge1, edge2);
Assert.assertNotEquals(edge1, properties);
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class DefaultEdgeTest method testOverwrite.
@Test
public void testOverwrite() {
DefaultEdge edge = new DefaultEdge(graphFactory());
edge.label("knows");
edge.name("2021-06-01");
edge.targetId(BytesId.of(1L));
Properties properties = new DefaultProperties(graphFactory());
properties.put("p1", new LongValue(1L));
properties.put("p2", new DoubleValue(2.0D));
edge.properties(properties);
Assert.assertEquals("knows", edge.label());
Assert.assertEquals("2021-06-01", edge.name());
Assert.assertEquals(BytesId.of(1L), edge.targetId());
Assert.assertEquals(properties, edge.properties());
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class StreamGraphOutputInputTest method testWriteReadVertex.
@Test
public void testWriteReadVertex() throws Exception {
Id longId = BytesId.of(100L);
LongValue longValue = new LongValue(999L);
Vertex vertex = graphFactory().createVertex(longId, longValue);
Properties properties = graphFactory().createProperties();
properties.put("age", new LongValue(20L));
vertex.properties(properties);
byte[] bytes;
try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
StreamGraphOutput output = newStreamGraphOutput(bao);
output.writeVertex(vertex);
bytes = bao.toByteArray();
}
try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
StreamGraphInput input = newStreamGraphInput(bai);
assertVertexEqualWithoutValue(vertex, input.readVertex());
}
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class StreamGraphInput method readProperties.
private Properties readProperties(RandomAccessInput in) throws IOException {
Properties properties = this.graphFactory.createProperties();
int size = in.readInt();
for (int i = 0; i < size; i++) {
String key = in.readUTF();
Value value = this.readValue(in);
properties.put(key, value);
}
return properties;
}
use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.
the class StreamGraphInput method readEdges.
@Override
public Vertex readEdges() throws IOException {
Vertex vertex = this.graphFactory.createVertex();
KvEntryReader reader = this.in.readEntry(in -> {
// Read id
vertex.id(readId(in));
});
if (this.frequency == EdgeFrequency.SINGLE) {
while (reader.hasRemaining()) {
Edge edge = this.graphFactory.createEdge();
// Only use targetId as subKey, use properties as subValue
reader.readSubKv(in -> {
edge.targetId(readId(in));
}, in -> {
edge.properties(readProperties(in));
});
vertex.addEdge(edge);
}
} else if (this.frequency == EdgeFrequency.SINGLE_PER_LABEL) {
while (reader.hasRemaining()) {
Edge edge = this.graphFactory.createEdge();
// Use label + targetId as subKey, use properties as subValue
reader.readSubKv(in -> {
edge.label(readLabel(in));
edge.targetId(readId(in));
}, in -> {
edge.properties(readProperties(in));
});
vertex.addEdge(edge);
}
} else {
assert this.frequency == EdgeFrequency.MULTIPLE;
while (reader.hasRemaining()) {
Edge edge = this.graphFactory.createEdge();
/*
* Use label + sortValues + targetId as subKey,
* use properties as subValue
*/
reader.readSubKv(in -> {
edge.label(readLabel(in));
edge.name(readLabel(in));
edge.targetId(readId(in));
}, in -> {
edge.properties(this.readProperties(in));
});
vertex.addEdge(edge);
}
}
return vertex;
}
Aggregations