Search in sources :

Example 31 with Id

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

the class VertexLabelBuilder method build.

@Override
public VertexLabel build() {
    Id id = this.validOrGenerateId(HugeType.VERTEX_LABEL, this.id, this.name);
    VertexLabel vertexLabel = new VertexLabel(this.graph(), id, this.name);
    vertexLabel.idStrategy(this.idStrategy);
    vertexLabel.enableLabelIndex(this.enableLabelIndex == null || this.enableLabelIndex);
    vertexLabel.ttl(this.ttl);
    if (this.ttlStartTime != null) {
        vertexLabel.ttlStartTime(this.graph().propertyKey(this.ttlStartTime).id());
    }
    // Assign properties
    for (String key : this.properties) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.property(propertyKey.id());
    }
    for (String key : this.primaryKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.primaryKey(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.nullableKey(propertyKey.id());
    }
    vertexLabel.userdata(this.userdata);
    return vertexLabel;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 32 with Id

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

the class HugeElement method getPropertyKeys.

public Set<Id> getPropertyKeys() {
    Set<Id> propKeys = InsertionOrderUtil.newSet();
    IntIterator keys = this.properties.keysView().intIterator();
    while (keys.hasNext()) {
        propKeys.add(IdGenerator.of(keys.next()));
    }
    return propKeys;
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id)

Example 33 with Id

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

the class HugeElement method updateToDefaultValueIfNone.

protected void updateToDefaultValueIfNone() {
    if (this.fresh() || this.defaultValueUpdated) {
        return;
    }
    this.defaultValueUpdated = true;
    // Set default value if needed
    for (Id pkeyId : this.schemaLabel().properties()) {
        if (this.properties.containsKey(intFromId(pkeyId))) {
            continue;
        }
        PropertyKey pkey = this.graph().propertyKey(pkeyId);
        Object value = pkey.defaultValue();
        if (value != null) {
            this.setProperty(this.newProperty(pkey, value));
        }
    }
    this.defaultValueUpdated = true;
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 34 with Id

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

the class HugeIndex method parseIndexId.

public static HugeIndex parseIndexId(HugeGraph graph, HugeType type, byte[] id) {
    Object values;
    IndexLabel indexLabel;
    if (type.isStringIndex()) {
        Id idObject = IdGenerator.of(id, IdType.STRING);
        String[] parts = SplicingIdGenerator.parse(idObject);
        E.checkState(parts.length == 2, "Invalid secondary index id");
        Id label = IdGenerator.ofStoredString(parts[0], IdType.LONG);
        indexLabel = IndexLabel.label(graph, label);
        values = parts[1];
    } else {
        assert type.isRange4Index() || type.isRange8Index();
        final int labelLength = 4;
        E.checkState(id.length > labelLength, "Invalid range index id");
        BytesBuffer buffer = BytesBuffer.wrap(id);
        Id label = IdGenerator.of(buffer.readInt());
        indexLabel = IndexLabel.label(graph, label);
        List<Id> fields = indexLabel.indexFields();
        E.checkState(fields.size() == 1, "Invalid range index fields");
        DataType dataType = graph.propertyKey(fields.get(0)).dataType();
        E.checkState(dataType.isNumber() || dataType.isDate(), "Invalid range index field type");
        Class<?> clazz = dataType.isNumber() ? dataType.clazz() : DataType.LONG.clazz();
        values = bytes2number(buffer.read(id.length - labelLength), clazz);
    }
    HugeIndex index = new HugeIndex(graph, indexLabel);
    index.fieldValues(values);
    return index;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) BytesBuffer(com.baidu.hugegraph.backend.serializer.BytesBuffer) DataType(com.baidu.hugegraph.type.define.DataType) Id(com.baidu.hugegraph.backend.id.Id)

Example 35 with Id

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

the class HugeVertex method edges.

@Watched(prefix = "vertex")
@Override
public Iterator<Edge> edges(Direction tinkerpopDir, String... edgeLabels) {
    Directions direction = Directions.convert(tinkerpopDir);
    // NOTE: get edges from memory if load all edges when loading vertex.
    if (this.existsEdges()) {
        return this.getEdges(direction, edgeLabels);
    }
    Id[] edgeLabelIds = this.graph().mapElName2Id(edgeLabels);
    Query query = GraphTransaction.constructEdgesQuery(this.id(), direction, edgeLabelIds);
    return this.graph().edges(query);
}
Also used : Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

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