All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.graphscope.groot.sdk.schema.Edge Maven / Gradle / Ivy

There is a newer version: 0.28.1
Show newest version
package com.alibaba.graphscope.groot.sdk.schema;

import com.alibaba.graphscope.proto.groot.*;

import java.util.Map;

public class Edge {
    public String label;
    public String srcLabel;
    public String dstLabel;
    public Map srcPk;
    public Map dstPk;
    public Map properties;

    public long eid;

    /**
     * Construct an edge
     * @param label edge label
     * @param srcLabel source vertex label
     * @param dstLabel destination vertex label
     * @param srcPk source primary keys
     * @param dstPk destination primary keys
     * @param properties edge properties
     */
    public Edge(
            String label,
            String srcLabel,
            String dstLabel,
            Map srcPk,
            Map dstPk,
            Map properties) {
        this.label = label;
        this.srcLabel = srcLabel;
        this.dstLabel = dstLabel;
        this.srcPk = srcPk;
        this.dstPk = dstPk;
        this.properties = properties;
    }

    public Edge(
            String label,
            String srcLabel,
            String dstLabel,
            Map srcPk,
            Map dstPk) {
        this(label, srcLabel, dstLabel, srcPk, dstPk, null);
    }

    public Edge(String label, Vertex src, Vertex dst, Map properties) {
        this(
                label,
                src.getLabel(),
                dst.getLabel(),
                src.getProperties(),
                dst.getProperties(),
                properties);
    }

    public Edge(String label, Vertex src, Vertex dst) {
        this(label, src, dst, null);
    }

    public void setEid(long eid) {
        this.eid = eid;
    }

    public String getLabel() {
        return label;
    }

    public String getSrcLabel() {
        return srcLabel;
    }

    public String getDstLabel() {
        return dstLabel;
    }

    public Map getSrcPk() {
        return srcPk;
    }

    public Map getDstPk() {
        return dstPk;
    }

    public Map getProperties() {
        return properties;
    }

    public EdgeRecordKeyPb toEdgeRecordKey() {
        return EdgeRecordKeyPb.newBuilder()
                .setLabel(label)
                .setSrcVertexKey(toVertexRecordKey(srcLabel, srcPk))
                .setDstVertexKey(toVertexRecordKey(dstLabel, dstPk))
                .setInnerId(eid)
                .build();
    }

    public DataRecordPb toDataRecord() {
        DataRecordPb.Builder builder =
                DataRecordPb.newBuilder().setEdgeRecordKey(toEdgeRecordKey());
        if (properties != null) {
            builder.putAllProperties(properties);
        }
        return builder.build();
    }

    public WriteRequestPb toWriteRequest(WriteTypePb writeType) {
        return WriteRequestPb.newBuilder()
                .setWriteType(writeType)
                .setDataRecord(toDataRecord())
                .build();
    }

    private VertexRecordKeyPb toVertexRecordKey(String label, Map properties) {
        VertexRecordKeyPb.Builder builder = VertexRecordKeyPb.newBuilder().setLabel(label);
        builder.putAllPkProperties(properties);
        return builder.build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy