use of com.baidu.hugegraph.structure.HugeEdge 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.structure.HugeEdge 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;
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class BinarySerializer method readEdge.
@Override
public HugeEdge readEdge(HugeGraph graph, BackendEntry bytesEntry) {
HugeVertex vertex = this.readVertex(graph, bytesEntry);
Collection<HugeEdge> edges = vertex.getEdges();
if (edges.size() != 1) {
E.checkState(false, "Expect 1 edge in vertex, but got %s", edges.size());
}
return edges.iterator().next();
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class CustomizedCrosspointsTraverser method crosspointsPaths.
public CrosspointsPaths crosspointsPaths(Iterator<Vertex> vertices, List<PathPattern> pathPatterns, long capacity, long limit) {
E.checkArgument(vertices.hasNext(), "The source vertices can't be empty");
E.checkArgument(!pathPatterns.isEmpty(), "The steps pattern can't be empty");
checkCapacity(capacity);
checkLimit(limit);
MultivaluedMap<Id, Node> initialSources = newMultivalueMap();
List<HugeVertex> verticesList = newList();
while (vertices.hasNext()) {
HugeVertex vertex = (HugeVertex) vertices.next();
verticesList.add(vertex);
Node node = new Node(vertex.id(), null);
initialSources.add(vertex.id(), node);
}
List<Path> paths = newList();
for (PathPattern pathPattern : pathPatterns) {
MultivaluedMap<Id, Node> sources = initialSources;
int stepNum = pathPattern.size();
long access = 0;
MultivaluedMap<Id, Node> newVertices = null;
for (Step step : pathPattern.steps()) {
stepNum--;
newVertices = newMultivalueMap();
Iterator<Edge> edges;
// Traversal vertices of previous level
for (Map.Entry<Id, List<Node>> entry : sources.entrySet()) {
List<Node> adjacency = newList();
edges = this.edgesOfVertex(entry.getKey(), step.edgeStep);
while (edges.hasNext()) {
HugeEdge edge = (HugeEdge) edges.next();
Id target = edge.id().otherVertexId();
for (Node n : entry.getValue()) {
// If have loop, skip target
if (n.contains(target)) {
continue;
}
Node newNode = new Node(target, n);
adjacency.add(newNode);
checkCapacity(capacity, ++access, "customized crosspoints");
}
}
// Add current node's adjacent nodes
for (Node node : adjacency) {
newVertices.add(node.id(), node);
}
}
// Re-init sources
sources = newVertices;
}
assert stepNum == 0;
for (List<Node> nodes : newVertices.values()) {
for (Node n : nodes) {
paths.add(new Path(n.path()));
}
}
}
return intersectionPaths(verticesList, paths, limit);
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class HugeTraverser method edgesOfVertex.
private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep, boolean mustAllSK) {
Id[] edgeLabels = edgeStep.edgeLabels();
Query query = GraphTransaction.constructEdgesQuery(source, edgeStep.direction(), edgeLabels);
ConditionQuery filter = null;
if (mustAllSK) {
this.fillFilterBySortKeys(query, edgeLabels, edgeStep.properties());
} else {
filter = (ConditionQuery) query.copy();
this.fillFilterByProperties(filter, edgeStep.properties());
}
query.capacity(Query.NO_CAPACITY);
if (edgeStep.limit() != NO_LIMIT) {
query.limit(edgeStep.limit());
}
Iterator<Edge> edges = this.graph().edges(query);
if (filter != null) {
ConditionQuery finalFilter = filter;
edges = new FilterIterator<>(edges, (e) -> {
return finalFilter.test((HugeEdge) e);
});
}
return edgeStep.skipSuperNodeIfNeeded(edges);
}
Aggregations