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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations