use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class StandardHugeGraph method edgeLabel.
@Override
public EdgeLabel edgeLabel(String name) {
EdgeLabel el = this.schemaTransaction().getEdgeLabel(name);
E.checkArgument(el != null, "Undefined edge label: '%s'", name);
return el;
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class HugeGraph method mapElName2Id.
default Id[] mapElName2Id(String[] edgeLabels) {
Id[] ids = new Id[edgeLabels.length];
for (int i = 0; i < edgeLabels.length; i++) {
EdgeLabel edgeLabel = this.edgeLabel(edgeLabels[i]);
ids[i] = edgeLabel.id();
}
return ids;
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class RelationshipManager method queryRelationship.
private Iterator<Edge> queryRelationship(Id source, Directions direction, String label, Map<String, Object> conditions, long limit) {
ConditionQuery query = new ConditionQuery(HugeType.EDGE);
EdgeLabel el = this.graph().edgeLabel(label);
if (direction == null) {
direction = Directions.OUT;
}
if (source != null) {
query.eq(HugeKeys.OWNER_VERTEX, source);
query.eq(HugeKeys.DIRECTION, direction);
}
if (label != null) {
query.eq(HugeKeys.LABEL, el.id());
}
for (Map.Entry<String, Object> entry : conditions.entrySet()) {
PropertyKey pk = this.graph().propertyKey(entry.getKey());
query.query(Condition.eq(pk.id(), entry.getValue()));
}
query.showHidden(true);
if (limit != NO_LIMIT) {
query.limit(limit);
}
Iterator<Edge> edges = this.tx().queryEdges(query);
if (limit == NO_LIMIT) {
return edges;
}
long[] size = new long[1];
return new MapperIterator<>(edges, edge -> {
if (++size[0] > limit) {
return null;
}
return edge;
});
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class TextSerializer method parseEdge.
/**
* Parse an edge from a column item
*/
private void parseEdge(String colName, String colValue, HugeVertex vertex) {
String[] colParts = EdgeId.split(colName);
HugeGraph graph = vertex.graph();
boolean direction = colParts[0].equals(EDGE_OUT_TYPE);
String sortValues = readEdgeName(colParts[2]);
EdgeLabel edgeLabel = graph.edgeLabelOrNone(readId(colParts[1]));
Id otherVertexId = readEntryId(colParts[3]);
// Construct edge
HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
String[] valParts = colValue.split(VALUE_SPLITOR);
// Parse edge expired time
String name = this.formatSyspropName(HugeKeys.EXPIRED_TIME);
E.checkState(valParts[1].equals(name), "Invalid system property name '%s'", valParts[1]);
edge.expiredTime(JsonUtil.fromJson(valParts[2], Long.class));
// Edge properties
for (int i = 3; i < valParts.length; i += 2) {
this.parseProperty(valParts[i], valParts[i + 1], edge);
}
}
use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.
the class BinarySerializer method parseEdge.
protected void parseEdge(BackendColumn col, HugeVertex vertex, HugeGraph graph) {
// owner-vertex + dir + edge-label + sort-values + other-vertex
BytesBuffer buffer = BytesBuffer.wrap(col.name);
if (this.keyWithIdPrefix) {
// Consume owner-vertex id
buffer.readId();
}
byte type = buffer.read();
Id labelId = buffer.readId();
String sortValues = buffer.readStringWithEnding();
Id otherVertexId = buffer.readId();
boolean direction = EdgeId.isOutDirectionFromCode(type);
EdgeLabel edgeLabel = graph.edgeLabelOrNone(labelId);
// Construct edge
HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
// Parse edge-id + edge-properties
buffer = BytesBuffer.wrap(col.value);
// Id id = buffer.readId();
// Parse edge properties
this.parseProperties(buffer, edge);
// Parse edge expired time if needed
if (edge.hasTtl()) {
this.parseExpiredTime(buffer, edge);
}
}
Aggregations