Search in sources :

Example 91 with Id

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

the class TextSerializer method readIndexLabel.

@Override
public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TextBackendEntry entry = this.convertEntry(backendEntry);
    Id id = readId(entry.id());
    String name = JsonUtil.fromJson(entry.column(HugeKeys.NAME), String.class);
    String baseType = entry.column(HugeKeys.BASE_TYPE);
    String baseValue = entry.column(HugeKeys.BASE_VALUE);
    String indexType = entry.column(HugeKeys.INDEX_TYPE);
    String indexFields = entry.column(HugeKeys.FIELDS);
    String status = entry.column(HugeKeys.STATUS);
    IndexLabel indexLabel = new IndexLabel(graph, id, name);
    indexLabel.baseType(JsonUtil.fromJson(baseType, HugeType.class));
    indexLabel.baseValue(readId(baseValue));
    indexLabel.indexType(JsonUtil.fromJson(indexType, IndexType.class));
    indexLabel.indexFields(readIds(indexFields));
    readUserdata(indexLabel, entry);
    indexLabel.status(JsonUtil.fromJson(status, SchemaStatus.class));
    return indexLabel;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) IndexType(com.baidu.hugegraph.type.define.IndexType) HugeType(com.baidu.hugegraph.type.HugeType) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 92 with Id

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

the class TextSerializer method readVertexLabel.

@Override
public VertexLabel readVertexLabel(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TextBackendEntry entry = this.convertEntry(backendEntry);
    Id id = readId(entry.id());
    String name = JsonUtil.fromJson(entry.column(HugeKeys.NAME), String.class);
    String idStrategy = entry.column(HugeKeys.ID_STRATEGY);
    String properties = entry.column(HugeKeys.PROPERTIES);
    String primaryKeys = entry.column(HugeKeys.PRIMARY_KEYS);
    String nullableKeys = entry.column(HugeKeys.NULLABLE_KEYS);
    String indexLabels = entry.column(HugeKeys.INDEX_LABELS);
    String enableLabelIndex = entry.column(HugeKeys.ENABLE_LABEL_INDEX);
    String status = entry.column(HugeKeys.STATUS);
    VertexLabel vertexLabel = new VertexLabel(graph, id, name);
    vertexLabel.idStrategy(JsonUtil.fromJson(idStrategy, IdStrategy.class));
    vertexLabel.properties(readIds(properties));
    vertexLabel.primaryKeys(readIds(primaryKeys));
    vertexLabel.nullableKeys(readIds(nullableKeys));
    vertexLabel.addIndexLabels(readIds(indexLabels));
    vertexLabel.enableLabelIndex(JsonUtil.fromJson(enableLabelIndex, Boolean.class));
    readUserdata(vertexLabel, entry);
    vertexLabel.status(JsonUtil.fromJson(status, SchemaStatus.class));
    return vertexLabel;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IdStrategy(com.baidu.hugegraph.type.define.IdStrategy) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 93 with Id

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

the class TextSerializer method writeIds.

private static String writeIds(Collection<Id> ids) {
    Object[] array = new Object[ids.size()];
    int i = 0;
    for (Id id : ids) {
        if (id.number()) {
            array[i++] = id.asLong();
        } else {
            array[i++] = id.asString();
        }
    }
    return JsonUtil.toJson(array);
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Example 94 with Id

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

the class BinarySerializer method writeIndex.

@Override
public BackendEntry writeIndex(HugeIndex index) {
    BinaryBackendEntry entry;
    if (index.fieldValues() == null && index.elementIds().size() == 0) {
        /*
             * When field-values is null and elementIds size is 0, it is
             * meaningful for deletion of index data by index label.
             * TODO: improve
             */
        entry = this.formatILDeletion(index);
    } else {
        Id id = index.id();
        HugeType type = index.type();
        byte[] value = null;
        if (!type.isNumericIndex() && indexIdLengthExceedLimit(id)) {
            id = index.hashId();
            // Save field-values as column value if the key is a hash string
            value = StringEncoding.encode(index.fieldValues().toString());
        }
        entry = newBackendEntry(type, id);
        if (index.indexLabel().olap()) {
            entry.olap(true);
        }
        entry.column(this.formatIndexName(index), value);
        entry.subId(index.elementId());
        if (index.hasTtl()) {
            entry.ttl(index.ttl());
        }
    }
    return entry;
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeType(com.baidu.hugegraph.type.HugeType)

Example 95 with Id

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

the class BinarySerializer method formatLabel.

protected BackendColumn formatLabel(HugeElement elem) {
    BackendColumn col = new BackendColumn();
    col.name = this.formatSyspropName(elem.id(), HugeKeys.LABEL);
    Id label = elem.schemaLabel().id();
    BytesBuffer buffer = BytesBuffer.allocate(label.length() + 1);
    col.value = buffer.writeId(label).bytes();
    return col;
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) 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