Search in sources :

Example 1 with IdWithExpiredTime

use of com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime in project incubator-hugegraph by apache.

the class TextSerializer method readElementIds.

private static IdWithExpiredTime[] readElementIds(String str) {
    Object[] values = JsonUtil.fromJson(str, Object[].class);
    IdWithExpiredTime[] ids = new IdWithExpiredTime[values.length];
    for (int i = 0; i < values.length; i++) {
        Object idValue;
        long expiredTime;
        if (values[i] instanceof Map) {
            @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) values[i];
            idValue = map.get(HugeKeys.ID.string());
            expiredTime = ((Number) map.get(HugeKeys.EXPIRED_TIME.string())).longValue();
        } else {
            idValue = values[i];
            expiredTime = 0L;
        }
        Id id;
        if (idValue instanceof Number) {
            id = IdGenerator.of(((Number) idValue).longValue());
        } else {
            assert idValue instanceof String;
            id = IdGenerator.of(idValue.toString());
        }
        ids[i] = new IdWithExpiredTime(id, expiredTime);
    }
    return ids;
}
Also used : IdWithExpiredTime(com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with IdWithExpiredTime

use of com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime in project incubator-hugegraph by apache.

the class TextSerializer method readIndex.

@Override
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry backendEntry) {
    E.checkNotNull(graph, "serializer graph");
    if (backendEntry == null) {
        return null;
    }
    TextBackendEntry entry = this.convertEntry(backendEntry);
    String indexValues = entry.column(formatSyspropName(HugeKeys.FIELD_VALUES));
    String indexLabelId = entry.column(formatSyspropName(HugeKeys.INDEX_LABEL_ID));
    String elemIds = entry.column(formatSyspropName(HugeKeys.ELEMENT_IDS));
    IndexLabel indexLabel = IndexLabel.label(graph, readId(indexLabelId));
    HugeIndex index = new HugeIndex(graph, indexLabel);
    index.fieldValues(JsonUtil.fromJson(indexValues, Object.class));
    for (IdWithExpiredTime elemId : readElementIds(elemIds)) {
        long expiredTime = elemId.expiredTime();
        Id id;
        if (indexLabel.queryType().isEdge()) {
            id = EdgeId.parse(elemId.id().asString());
        } else {
            id = elemId.id();
        }
        index.elementIds(id, expiredTime);
    }
    // Memory backend might return empty BackendEntry
    return index;
}
Also used : IdWithExpiredTime(com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Aggregations

EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 Id (com.baidu.hugegraph.backend.id.Id)2 IdWithExpiredTime (com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime)2 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)1 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1