Search in sources :

Example 11 with HugeEdge

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;
}
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 HugeEdge

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

Example 13 with HugeEdge

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

Example 14 with HugeEdge

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);
}
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 HugeEdge

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);
}
Also used : QueryResults(com.baidu.hugegraph.backend.query.QueryResults) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) CollectionUtil(com.baidu.hugegraph.util.CollectionUtil) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) FilterIterator(com.baidu.hugegraph.iterator.FilterIterator) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) HugeGraph(com.baidu.hugegraph.HugeGraph) Map(java.util.Map) Query(com.baidu.hugegraph.backend.query.Query) CollectionFactory(com.baidu.hugegraph.util.collection.CollectionFactory) E(com.baidu.hugegraph.util.E) CoreOptions(com.baidu.hugegraph.config.CoreOptions) Edge(org.apache.tinkerpop.gremlin.structure.Edge) MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) ExtendableIterator(com.baidu.hugegraph.iterator.ExtendableIterator) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) EdgeStep(com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InsertionOrderUtil(com.baidu.hugegraph.util.InsertionOrderUtil) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) LimitIterator(com.baidu.hugegraph.iterator.LimitIterator) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched) Objects(java.util.Objects) MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) HugeException(com.baidu.hugegraph.HugeException) List(java.util.List) Log(com.baidu.hugegraph.util.Log) Directions(com.baidu.hugegraph.type.define.Directions) Aggregate(com.baidu.hugegraph.backend.query.Aggregate) Id(com.baidu.hugegraph.backend.id.Id) TraversalUtil(com.baidu.hugegraph.traversal.optimize.TraversalUtil) Collections(java.util.Collections) HugeType(com.baidu.hugegraph.type.HugeType) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Aggregations

HugeEdge (com.baidu.hugegraph.structure.HugeEdge)54 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)29 Id (com.baidu.hugegraph.backend.id.Id)26 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 Test (org.junit.Test)20 HugeGraph (com.baidu.hugegraph.HugeGraph)17 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)9 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 EdgeStep (com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep)6 Iterator (java.util.Iterator)6 List (java.util.List)6 Set (java.util.Set)6 HugeException (com.baidu.hugegraph.HugeException)5 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5