use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class TableBackendEntry method mergeable.
@Override
public boolean mergeable(BackendEntry other) {
if (!(other instanceof TableBackendEntry)) {
return false;
}
TableBackendEntry tableEntry = (TableBackendEntry) other;
Object selfId = this.column(HugeKeys.ID);
Object otherId = tableEntry.column(HugeKeys.ID);
if (!selfId.equals(otherId)) {
return false;
}
Id key = tableEntry.subId();
Object value = tableEntry.row().column(HugeKeys.PROPERTY_VALUE);
this.row().column(HugeKeys.PROPERTIES, key.asLong(), value);
return true;
}
use of com.baidu.hugegraph.backend.id.Id 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.id.Id in project incubator-hugegraph by apache.
the class TableSerializer method readVertex.
@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry backendEntry) {
E.checkNotNull(graph, "serializer graph");
if (backendEntry == null) {
return null;
}
TableBackendEntry entry = this.convertEntry(backendEntry);
assert entry.type().isVertex();
Id id = this.readId(entry.column(HugeKeys.ID));
Number label = entry.column(HugeKeys.LABEL);
Number expiredTime = entry.column(HugeKeys.EXPIRED_TIME);
VertexLabel vertexLabel = VertexLabel.NONE;
if (label != null) {
vertexLabel = graph.vertexLabelOrNone(this.toId(label));
}
HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
// Parse all properties of a Vertex
this.parseProperties(vertex, entry.row());
// Parse all edges of a Vertex
for (TableBackendEntry.Row edge : entry.subRows()) {
this.parseEdge(edge, vertex, graph);
}
// The expired time is null when this is fake vertex of edge or non-ttl
if (expiredTime != null) {
vertex.expiredTime(expiredTime.longValue());
}
return vertex;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class TableSerializer method parseEdge.
/**
* Parse an edge from a entry row
* @param row edge entry
* @param vertex null or the source vertex
* @param graph the HugeGraph context object
* @return the source vertex
*/
protected HugeEdge parseEdge(TableBackendEntry.Row row, HugeVertex vertex, HugeGraph graph) {
Object ownerVertexId = row.column(HugeKeys.OWNER_VERTEX);
Number dir = row.column(HugeKeys.DIRECTION);
boolean direction = EdgeId.isOutDirectionFromCode(dir.byteValue());
Number label = row.column(HugeKeys.LABEL);
String sortValues = row.column(HugeKeys.SORT_VALUES);
Object otherVertexId = row.column(HugeKeys.OTHER_VERTEX);
Number expiredTime = row.column(HugeKeys.EXPIRED_TIME);
if (vertex == null) {
Id ownerId = this.readId(ownerVertexId);
vertex = new HugeVertex(graph, ownerId, VertexLabel.NONE);
}
EdgeLabel edgeLabel = graph.edgeLabelOrNone(this.toId(label));
Id otherId = this.readId(otherVertexId);
// Construct edge
HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherId);
// Parse edge properties
this.parseProperties(edge, row);
// The expired time is null when the edge is non-ttl
long expired = edge.hasTtl() ? expiredTime.longValue() : 0L;
edge.expiredTime(expired);
return edge;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class TextSerializer method writeEdgeProperty.
@Override
public BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop) {
HugeEdge edge = prop.element();
Id id = IdGenerator.of(edge.idWithDirection().asString());
TextBackendEntry entry = newBackendEntry(edge.type(), id);
entry.subId(IdGenerator.of(prop.key()));
entry.column(this.formatEdgeName(edge), this.formatEdgeValue(edge));
return entry;
}
Aggregations