use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId in project incubator-hugegraph by apache.
the class BinarySerializer method writeQueryEdgePrefixCondition.
private Query writeQueryEdgePrefixCondition(ConditionQuery cq) {
int count = 0;
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
for (HugeKeys key : EdgeId.KEYS) {
Object value = cq.condition(key);
if (value != null) {
count++;
} else {
if (key == HugeKeys.DIRECTION) {
// Direction is null, set to OUT
value = Directions.OUT;
} else {
break;
}
}
if (key == HugeKeys.OWNER_VERTEX || key == HugeKeys.OTHER_VERTEX) {
writePartitionedId(HugeType.EDGE, (Id) value, buffer);
} else if (key == HugeKeys.DIRECTION) {
byte t = ((Directions) value).type().code();
buffer.write(t);
} else if (key == HugeKeys.LABEL) {
assert value instanceof Id;
buffer.writeId((Id) value);
} else if (key == HugeKeys.SORT_VALUES) {
assert value instanceof String;
buffer.writeStringWithEnding((String) value);
} else {
assert false : key;
}
}
if (count > 0) {
assert count == cq.conditionsSize();
return prefixQuery(cq, new BinaryId(buffer.bytes(), null));
}
return null;
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId in project incubator-hugegraph by apache.
the class BinarySerializer method newBackendEntry.
@Override
protected BinaryBackendEntry newBackendEntry(HugeType type, Id id) {
if (type.isVertex()) {
BytesBuffer buffer = BytesBuffer.allocate(2 + 1 + id.length());
writePartitionedId(HugeType.VERTEX, id, buffer);
return new BinaryBackendEntry(type, new BinaryId(buffer.bytes(), id));
}
if (type.isEdge()) {
E.checkState(id instanceof BinaryId, "Expect a BinaryId for BackendEntry with edge id");
return new BinaryBackendEntry(type, (BinaryId) id);
}
if (type.isIndex()) {
if (this.enablePartition) {
if (type.isStringIndex()) {
// TODO: add string index partition
}
if (type.isNumericIndex()) {
// TODO: add numeric index partition
}
}
BytesBuffer buffer = BytesBuffer.allocate(1 + id.length());
byte[] idBytes = buffer.writeIndexId(id, type).bytes();
return new BinaryBackendEntry(type, new BinaryId(idBytes, id));
}
BytesBuffer buffer = BytesBuffer.allocate(1 + id.length());
byte[] idBytes = buffer.writeId(id).bytes();
return new BinaryBackendEntry(type, new BinaryId(idBytes, id));
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId in project incubator-hugegraph by apache.
the class BytesBuffer method parseId.
public BinaryId parseId(HugeType type, boolean enablePartition) {
if (type.isIndex()) {
return this.readIndexId(type);
}
// Parse id from bytes
if ((type.isVertex() || type.isEdge()) && enablePartition) {
this.readShort();
}
int start = this.buffer.position();
/*
* Since edge id in edges table doesn't prefix with leading 0x7e,
* so readId() will return the source vertex id instead of edge id,
* can't call: type.isEdge() ? this.readEdgeId() : this.readId();
*/
Id id = this.readId();
int end = this.buffer.position();
int len = end - start;
byte[] bytes = new byte[len];
System.arraycopy(this.array(), start, bytes, 0, len);
return new BinaryId(bytes, id);
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId in project incubator-hugegraph by apache.
the class BinarySerializer method prefixQuery.
private static Query prefixQuery(ConditionQuery query, Id prefix) {
Query newQuery;
if (query.paging() && !query.page().isEmpty()) {
/*
* If used paging and the page number is not empty, deserialize
* the page to id and use it as the starting row for this query
*/
byte[] position = PageState.fromString(query.page()).position();
E.checkArgument(Bytes.compare(position, prefix.asBytes()) >= 0, "Invalid page out of lower bound");
BinaryId start = new BinaryId(position, null);
newQuery = new IdPrefixQuery(query, start, prefix);
} else {
newQuery = new IdPrefixQuery(query, prefix);
}
return newQuery;
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId in project incubator-hugegraph by apache.
the class BinarySerializer method writeEdgeId.
private BinaryId writeEdgeId(Id id) {
EdgeId edgeId;
if (id instanceof EdgeId) {
edgeId = (EdgeId) id;
} else {
edgeId = EdgeId.parse(id.asString());
}
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
if (this.enablePartition) {
buffer.writeShort(getPartition(HugeType.EDGE, edgeId.ownerVertexId()));
buffer.writeEdgeId(edgeId);
} else {
buffer.writeEdgeId(edgeId);
}
return new BinaryId(buffer.bytes(), id);
}
Aggregations