Search in sources :

Example 1 with Edge

use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.

the class EdgesInputTest method addEdgeBuffer.

private static void addEdgeBuffer(Consumer<ManagedBuffer> 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);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 2 with Edge

use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.

the class EdgesInput method readEdges.

// TODO: use one reused Edges instance to read batches for each vertex.
private Edges readEdges(RandomAccessInput in) {
    try {
        int count = in.readFixedInt();
        Edges edges = this.graphFactory.createEdges(count);
        if (this.frequency == EdgeFrequency.SINGLE) {
            for (int i = 0; i < count; i++) {
                Edge edge = this.graphFactory.createEdge();
                // Only use targetId as subKey, use props as subValue
                edge.targetId(StreamGraphInput.readId(in));
                // Read subValue
                Properties props = this.graphFactory.createProperties();
                props.read(in);
                edge.properties(props);
                edges.add(edge);
            }
        } else if (this.frequency == EdgeFrequency.SINGLE_PER_LABEL) {
            for (int i = 0; i < count; i++) {
                Edge edge = this.graphFactory.createEdge();
                // Use label + targetId as subKey, use props as subValue
                edge.label(StreamGraphInput.readLabel(in));
                edge.targetId(StreamGraphInput.readId(in));
                // Read subValue
                Properties props = this.graphFactory.createProperties();
                props.read(in);
                edge.properties(props);
                edges.add(edge);
            }
        } else {
            assert this.frequency == EdgeFrequency.MULTIPLE;
            for (int i = 0; i < count; i++) {
                Edge edge = this.graphFactory.createEdge();
                /*
                     * Use label + sortValues + targetId as subKey,
                     * use properties as subValue
                     */
                edge.label(StreamGraphInput.readLabel(in));
                edge.name(StreamGraphInput.readLabel(in));
                edge.targetId(StreamGraphInput.readId(in));
                // Read subValue
                Properties props = this.graphFactory.createProperties();
                props.read(in);
                edge.properties(props);
                edges.add(edge);
            }
        }
        return edges;
    } catch (IOException e) {
        throw new ComputerException("Failed to read edges from input '%s'", e, this.edgeFile.getAbsoluteFile());
    }
}
Also used : IOException(java.io.IOException) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 3 with Edge

use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.

the class CsvStructGraphOutput method writeEdges.

@Override
public void writeEdges(Edges edges) throws IOException {
    this.writeArrayStart();
    int size = edges.size();
    int i = 0;
    for (Edge edge : edges) {
        this.writeEdge(edge);
        if (++i < size) {
            this.writeSplitter();
        }
    }
    this.writeArrayEnd();
}
Also used : Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 4 with Edge

use of com.baidu.hugegraph.computer.core.graph.edge.Edge 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();
}
Also used : ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Map(java.util.Map) EdgeFrequency(com.baidu.hugegraph.computer.core.config.EdgeFrequency) Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) EntryOutput(com.baidu.hugegraph.computer.core.store.entry.EntryOutput) IOException(java.io.IOException) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Value(com.baidu.hugegraph.computer.core.graph.value.Value) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 5 with Edge

use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.

the class JsonStructGraphOutput method writeEdges.

@Override
public void writeEdges(Edges edges) throws IOException {
    this.writeArrayStart();
    int size = edges.size();
    int i = 0;
    for (Edge edge : edges) {
        this.writeEdge(edge);
        if (++i < size) {
            this.writeSplitter();
        }
    }
    this.writeArrayEnd();
}
Also used : Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Aggregations

Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)28 Id (com.baidu.hugegraph.computer.core.graph.id.Id)12 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)11 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)11 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)10 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)8 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)5 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)4 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)3 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)3 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)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 Value (com.baidu.hugegraph.computer.core.graph.value.Value)2 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)2 KvEntryWriter (com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter)2 Config (com.baidu.hugegraph.computer.core.config.Config)1 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)1