Search in sources :

Example 1 with KvEntryReader

use of com.baidu.hugegraph.computer.core.store.entry.KvEntryReader 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

ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)1 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)1 Config (com.baidu.hugegraph.computer.core.config.Config)1 EdgeFrequency (com.baidu.hugegraph.computer.core.config.EdgeFrequency)1 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)1 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)1 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)1 Id (com.baidu.hugegraph.computer.core.graph.id.Id)1 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)1 Value (com.baidu.hugegraph.computer.core.graph.value.Value)1 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)1 EntryInput (com.baidu.hugegraph.computer.core.store.entry.EntryInput)1 KvEntryReader (com.baidu.hugegraph.computer.core.store.entry.KvEntryReader)1 IOException (java.io.IOException)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1