Search in sources :

Example 31 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class StandardHugeGraph method edgeLabel.

@Override
public EdgeLabel edgeLabel(String name) {
    EdgeLabel el = this.schemaTransaction().getEdgeLabel(name);
    E.checkArgument(el != null, "Undefined edge label: '%s'", name);
    return el;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel)

Example 32 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class HugeGraph method mapElName2Id.

default Id[] mapElName2Id(String[] edgeLabels) {
    Id[] ids = new Id[edgeLabels.length];
    for (int i = 0; i < edgeLabels.length; i++) {
        EdgeLabel edgeLabel = this.edgeLabel(edgeLabels[i]);
        ids[i] = edgeLabel.id();
    }
    return ids;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id)

Example 33 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class RelationshipManager method queryRelationship.

private Iterator<Edge> queryRelationship(Id source, Directions direction, String label, Map<String, Object> conditions, long limit) {
    ConditionQuery query = new ConditionQuery(HugeType.EDGE);
    EdgeLabel el = this.graph().edgeLabel(label);
    if (direction == null) {
        direction = Directions.OUT;
    }
    if (source != null) {
        query.eq(HugeKeys.OWNER_VERTEX, source);
        query.eq(HugeKeys.DIRECTION, direction);
    }
    if (label != null) {
        query.eq(HugeKeys.LABEL, el.id());
    }
    for (Map.Entry<String, Object> entry : conditions.entrySet()) {
        PropertyKey pk = this.graph().propertyKey(entry.getKey());
        query.query(Condition.eq(pk.id(), entry.getValue()));
    }
    query.showHidden(true);
    if (limit != NO_LIMIT) {
        query.limit(limit);
    }
    Iterator<Edge> edges = this.tx().queryEdges(query);
    if (limit == NO_LIMIT) {
        return edges;
    }
    long[] size = new long[1];
    return new MapperIterator<>(edges, edge -> {
        if (++size[0] > limit) {
            return null;
        }
        return edge;
    });
}
Also used : MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 34 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class TextSerializer method parseEdge.

/**
 * Parse an edge from a column item
 */
private void parseEdge(String colName, String colValue, HugeVertex vertex) {
    String[] colParts = EdgeId.split(colName);
    HugeGraph graph = vertex.graph();
    boolean direction = colParts[0].equals(EDGE_OUT_TYPE);
    String sortValues = readEdgeName(colParts[2]);
    EdgeLabel edgeLabel = graph.edgeLabelOrNone(readId(colParts[1]));
    Id otherVertexId = readEntryId(colParts[3]);
    // Construct edge
    HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
    String[] valParts = colValue.split(VALUE_SPLITOR);
    // Parse edge expired time
    String name = this.formatSyspropName(HugeKeys.EXPIRED_TIME);
    E.checkState(valParts[1].equals(name), "Invalid system property name '%s'", valParts[1]);
    edge.expiredTime(JsonUtil.fromJson(valParts[2], Long.class));
    // Edge properties
    for (int i = 3; i < valParts.length; i += 2) {
        this.parseProperty(valParts[i], valParts[i + 1], edge);
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Example 35 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class BinarySerializer method parseEdge.

protected void parseEdge(BackendColumn col, HugeVertex vertex, HugeGraph graph) {
    // owner-vertex + dir + edge-label + sort-values + other-vertex
    BytesBuffer buffer = BytesBuffer.wrap(col.name);
    if (this.keyWithIdPrefix) {
        // Consume owner-vertex id
        buffer.readId();
    }
    byte type = buffer.read();
    Id labelId = buffer.readId();
    String sortValues = buffer.readStringWithEnding();
    Id otherVertexId = buffer.readId();
    boolean direction = EdgeId.isOutDirectionFromCode(type);
    EdgeLabel edgeLabel = graph.edgeLabelOrNone(labelId);
    // Construct edge
    HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
    // Parse edge-id + edge-properties
    buffer = BytesBuffer.wrap(col.value);
    // Id id = buffer.readId();
    // Parse edge properties
    this.parseProperties(buffer, edge);
    // Parse edge expired time if needed
    if (edge.hasTtl()) {
        this.parseExpiredTime(buffer, edge);
    }
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Aggregations

EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)58 Test (org.junit.Test)22 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)19 Id (com.baidu.hugegraph.backend.id.Id)16 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)12 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)11 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Date (java.util.Date)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)3 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 SchemaStatus (com.baidu.hugegraph.type.define.SchemaStatus)3