use of com.baidu.hugegraph.structure.HugeVertex 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.HugeVertex 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.HugeVertex in project incubator-hugegraph by apache.
the class TextSerializer method readVertex.
@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry backendEntry) {
E.checkNotNull(graph, "serializer graph");
if (backendEntry == null) {
return null;
}
TextBackendEntry entry = this.convertEntry(backendEntry);
// Parse label
String labelId = entry.column(this.formatSyspropName(HugeKeys.LABEL));
VertexLabel vertexLabel = VertexLabel.NONE;
if (labelId != null) {
vertexLabel = graph.vertexLabelOrNone(readId(labelId));
}
Id id = IdUtil.readString(entry.id().asString());
HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
String expiredTime = entry.column(this.formatSyspropName(HugeKeys.EXPIRED_TIME));
// Expired time is null when backend entry is fake vertex with edges
if (expiredTime != null) {
vertex.expiredTime(readLong(expiredTime));
}
// Parse all properties or edges of a Vertex
for (String name : entry.columnNames()) {
this.parseColumn(name, entry.column(name), vertex);
}
return vertex;
}
use of com.baidu.hugegraph.structure.HugeVertex 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.HugeVertex in project incubator-hugegraph by apache.
the class PersonalRankTraverser method getStartDirection.
private Directions getStartDirection(Id source, String label) {
// NOTE: The outer layer needs to ensure that the vertex Id is valid
HugeVertex vertex = (HugeVertex) graph().vertices(source).next();
VertexLabel vertexLabel = vertex.schemaLabel();
EdgeLabel edgeLabel = this.graph().edgeLabel(label);
Id sourceLabel = edgeLabel.sourceLabel();
Id targetLabel = edgeLabel.targetLabel();
E.checkArgument(edgeLabel.linkWithLabel(vertexLabel.id()), "The vertex '%s' doesn't link with edge label '%s'", source, label);
E.checkArgument(!sourceLabel.equals(targetLabel), "The edge label for personal rank must " + "link different vertex labels");
if (sourceLabel.equals(vertexLabel.id())) {
return Directions.OUT;
} else {
assert targetLabel.equals(vertexLabel.id());
return Directions.IN;
}
}
Aggregations