Search in sources :

Example 21 with Properties

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);
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DefaultEdge(com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) Test(org.junit.Test)

Example 22 with 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());
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DefaultEdge(com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) Test(org.junit.Test)

Example 23 with 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());
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 24 with Properties

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;
}
Also used : Value(com.baidu.hugegraph.computer.core.graph.value.Value) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties)

Example 25 with 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;
}
Also used : ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) Id(com.baidu.hugegraph.computer.core.graph.id.Id) EntryInput(com.baidu.hugegraph.computer.core.store.entry.EntryInput) EdgeFrequency(com.baidu.hugegraph.computer.core.config.EdgeFrequency) Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) IOException(java.io.IOException) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) Config(com.baidu.hugegraph.computer.core.config.Config) Value(com.baidu.hugegraph.computer.core.graph.value.Value) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) KvEntryReader(com.baidu.hugegraph.computer.core.store.entry.KvEntryReader) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) KvEntryReader(com.baidu.hugegraph.computer.core.store.entry.KvEntryReader) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Aggregations

Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)30 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)20 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)15 Test (org.junit.Test)12 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)11 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)9 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)7 Id (com.baidu.hugegraph.computer.core.graph.id.Id)6 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)5 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)5 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)3 Config (com.baidu.hugegraph.computer.core.config.Config)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3 IOException (java.io.IOException)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)2 EdgeFrequency (com.baidu.hugegraph.computer.core.config.EdgeFrequency)2