Search in sources :

Example 11 with HugeVertex

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;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 12 with HugeVertex

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();
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 13 with HugeVertex

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;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 14 with HugeVertex

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);
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeStep(com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) Map(java.util.Map)

Example 15 with HugeVertex

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;
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Aggregations

HugeVertex (com.baidu.hugegraph.structure.HugeVertex)58 Id (com.baidu.hugegraph.backend.id.Id)27 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)26 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)18 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)16 Test (org.junit.Test)16 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)10 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)9 HugeGraph (com.baidu.hugegraph.HugeGraph)8 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)7 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)6 HugeException (com.baidu.hugegraph.HugeException)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5 HugeProperty (com.baidu.hugegraph.structure.HugeProperty)4 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3