Search in sources :

Example 86 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class TableBackendEntry method mergeable.

@Override
public boolean mergeable(BackendEntry other) {
    if (!(other instanceof TableBackendEntry)) {
        return false;
    }
    TableBackendEntry tableEntry = (TableBackendEntry) other;
    Object selfId = this.column(HugeKeys.ID);
    Object otherId = tableEntry.column(HugeKeys.ID);
    if (!selfId.equals(otherId)) {
        return false;
    }
    Id key = tableEntry.subId();
    Object value = tableEntry.row().column(HugeKeys.PROPERTY_VALUE);
    this.row().column(HugeKeys.PROPERTIES, key.asLong(), value);
    return true;
}
Also used : Id(com.baidu.hugegraph.backend.id.Id)

Example 87 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class BytesBuffer method parseId.

public BinaryId parseId(HugeType type, boolean enablePartition) {
    if (type.isIndex()) {
        return this.readIndexId(type);
    }
    // Parse id from bytes
    if ((type.isVertex() || type.isEdge()) && enablePartition) {
        this.readShort();
    }
    int start = this.buffer.position();
    /*
         * Since edge id in edges table doesn't prefix with leading 0x7e,
         * so readId() will return the source vertex id instead of edge id,
         * can't call: type.isEdge() ? this.readEdgeId() : this.readId();
         */
    Id id = this.readId();
    int end = this.buffer.position();
    int len = end - start;
    byte[] bytes = new byte[len];
    System.arraycopy(this.array(), start, bytes, 0, len);
    return new BinaryId(bytes, id);
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id)

Example 88 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class TableSerializer method readVertex.

@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry backendEntry) {
    E.checkNotNull(graph, "serializer graph");
    if (backendEntry == null) {
        return null;
    }
    TableBackendEntry entry = this.convertEntry(backendEntry);
    assert entry.type().isVertex();
    Id id = this.readId(entry.column(HugeKeys.ID));
    Number label = entry.column(HugeKeys.LABEL);
    Number expiredTime = entry.column(HugeKeys.EXPIRED_TIME);
    VertexLabel vertexLabel = VertexLabel.NONE;
    if (label != null) {
        vertexLabel = graph.vertexLabelOrNone(this.toId(label));
    }
    HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
    // Parse all properties of a Vertex
    this.parseProperties(vertex, entry.row());
    // Parse all edges of a Vertex
    for (TableBackendEntry.Row edge : entry.subRows()) {
        this.parseEdge(edge, vertex, graph);
    }
    // The expired time is null when this is fake vertex of edge or non-ttl
    if (expiredTime != null) {
        vertex.expiredTime(expiredTime.longValue());
    }
    return vertex;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 89 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class TableSerializer method parseEdge.

/**
 * Parse an edge from a entry row
 * @param row edge entry
 * @param vertex null or the source vertex
 * @param graph the HugeGraph context object
 * @return the source vertex
 */
protected HugeEdge parseEdge(TableBackendEntry.Row row, HugeVertex vertex, HugeGraph graph) {
    Object ownerVertexId = row.column(HugeKeys.OWNER_VERTEX);
    Number dir = row.column(HugeKeys.DIRECTION);
    boolean direction = EdgeId.isOutDirectionFromCode(dir.byteValue());
    Number label = row.column(HugeKeys.LABEL);
    String sortValues = row.column(HugeKeys.SORT_VALUES);
    Object otherVertexId = row.column(HugeKeys.OTHER_VERTEX);
    Number expiredTime = row.column(HugeKeys.EXPIRED_TIME);
    if (vertex == null) {
        Id ownerId = this.readId(ownerVertexId);
        vertex = new HugeVertex(graph, ownerId, VertexLabel.NONE);
    }
    EdgeLabel edgeLabel = graph.edgeLabelOrNone(this.toId(label));
    Id otherId = this.readId(otherVertexId);
    // Construct edge
    HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherId);
    // Parse edge properties
    this.parseProperties(edge, row);
    // The expired time is null when the edge is non-ttl
    long expired = edge.hasTtl() ? expiredTime.longValue() : 0L;
    edge.expiredTime(expired);
    return edge;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 90 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class TextSerializer method writeEdgeProperty.

@Override
public BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop) {
    HugeEdge edge = prop.element();
    Id id = IdGenerator.of(edge.idWithDirection().asString());
    TextBackendEntry entry = newBackendEntry(edge.type(), id);
    entry.subId(IdGenerator.of(prop.key()));
    entry.column(this.formatEdgeName(edge), this.formatEdgeValue(edge));
    return entry;
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)381 Test (org.junit.Test)124 HugeGraph (com.baidu.hugegraph.HugeGraph)104 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)71 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)54 Timed (com.codahale.metrics.annotation.Timed)41 Produces (jakarta.ws.rs.Produces)40 AuthManager (com.baidu.hugegraph.auth.AuthManager)39 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)37 ArrayList (java.util.ArrayList)35 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)33 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)33 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)32 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)32 Directions (com.baidu.hugegraph.type.define.Directions)29 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)25 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)25 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)24 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 HugeType (com.baidu.hugegraph.type.HugeType)21