Search in sources :

Example 56 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeEdge method constructEdge.

@Watched
public static HugeEdge constructEdge(HugeVertex ownerVertex, boolean isOutEdge, EdgeLabel edgeLabel, String sortValues, Id otherVertexId) {
    HugeGraph graph = ownerVertex.graph();
    VertexLabel srcLabel = graph.vertexLabelOrNone(edgeLabel.sourceLabel());
    VertexLabel tgtLabel = graph.vertexLabelOrNone(edgeLabel.targetLabel());
    VertexLabel otherVertexLabel;
    if (isOutEdge) {
        ownerVertex.correctVertexLabel(srcLabel);
        otherVertexLabel = tgtLabel;
    } else {
        ownerVertex.correctVertexLabel(tgtLabel);
        otherVertexLabel = srcLabel;
    }
    HugeVertex otherVertex = new HugeVertex(graph, otherVertexId, otherVertexLabel);
    ownerVertex.propNotLoaded();
    otherVertex.propNotLoaded();
    HugeEdge edge = new HugeEdge(graph, null, edgeLabel);
    edge.name(sortValues);
    edge.vertices(isOutEdge, ownerVertex, otherVertex);
    edge.assignId();
    if (isOutEdge) {
        ownerVertex.addOutEdge(edge);
        otherVertex.addInEdge(edge.switchOwner());
    } else {
        ownerVertex.addInEdge(edge);
        otherVertex.addOutEdge(edge.switchOwner());
    }
    return edge;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 57 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeTraverser method edgesOfVertex.

@Watched
protected Iterator<Edge> edgesOfVertex(Id source, Directions dir, Id label, long limit) {
    Id[] labels = {};
    if (label != null) {
        labels = new Id[] { label };
    }
    Query query = GraphTransaction.constructEdgesQuery(source, dir, labels);
    if (limit != NO_LIMIT) {
        query.limit(limit);
    }
    return this.graph.edges(query);
}
Also used : Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 58 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class PathsTraverser method paths.

@Watched
public PathSet paths(Id sourceV, Directions sourceDir, Id targetV, Directions targetDir, String label, int depth, long degree, long capacity, long limit) {
    E.checkNotNull(sourceV, "source vertex id");
    E.checkNotNull(targetV, "target vertex id");
    this.checkVertexExist(sourceV, "source vertex");
    this.checkVertexExist(targetV, "target vertex");
    E.checkNotNull(sourceDir, "source direction");
    E.checkNotNull(targetDir, "target direction");
    E.checkArgument(sourceDir == targetDir || sourceDir == targetDir.opposite(), "Source direction must equal to target direction" + " or opposite to target direction");
    E.checkArgument(depth > 0 && depth <= DEFAULT_MAX_DEPTH, "The depth must be in (0, %s], but got: %s", DEFAULT_MAX_DEPTH, depth);
    checkDegree(degree);
    checkCapacity(capacity);
    checkLimit(limit);
    if (sourceV.equals(targetV)) {
        return PathSet.EMPTY;
    }
    Id labelId = this.getEdgeLabelId(label);
    Traverser traverser = new Traverser(sourceV, targetV, labelId, degree, capacity, limit);
    // We should stop early if walk backtrace or reach limit
    while (true) {
        if (--depth < 0 || traverser.reachLimit()) {
            break;
        }
        traverser.forward(targetV, sourceDir);
        if (--depth < 0 || traverser.reachLimit()) {
            break;
        }
        traverser.backward(sourceV, targetDir);
    }
    return traverser.paths();
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 59 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class PathsRecords method findPath.

@Watched
@Override
public PathSet findPath(Id target, Function<Id, Boolean> filter, boolean all, boolean ring) {
    assert all;
    int targetCode = this.code(target);
    int parentCode = this.current();
    PathSet paths = PathSet.EMPTY;
    // Traverse backtrace is not allowed, stop now
    if (this.parentsContain(targetCode)) {
        return paths;
    }
    // Add to current layer
    this.addPath(targetCode, parentCode);
    // If cross point exists, path found, concat them
    if (this.movingForward() && this.targetContains(targetCode)) {
        paths = this.linkPath(parentCode, targetCode, ring);
    }
    if (!this.movingForward() && this.sourceContains(targetCode)) {
        paths = this.linkPath(targetCode, parentCode, ring);
    }
    return paths;
}
Also used : PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 60 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method initBasicVertexLabelAndEdgeLabelExceptV.

@Watched
private void initBasicVertexLabelAndEdgeLabelExceptV(String defaultVL) {
    SchemaManager schema = this.graph.schema();
    if (!defaultVL.equals("person")) {
        schema.vertexLabel("person").properties("name", "age").nullableKeys("name", "age").ifNotExist().create();
    }
    schema.vertexLabel("software").properties("name", "lang").nullableKeys("name", "lang").ifNotExist().create();
    schema.vertexLabel("thing").properties("here").nullableKeys("here").ifNotExist().create();
    schema.vertexLabel("blah").properties("test").nullableKeys("test").ifNotExist().create();
    schema.edgeLabel("self").link(defaultVL, defaultVL).properties("__id", "test", "name", "some", "acl", "weight", "here", "to-change", "dropped", "not-dropped", "new", "to-drop", "short", "long").nullableKeys("__id", "test", "name", "some", "acl", "weight", "here", "to-change", "dropped", "not-dropped", "new", "to-drop", "short", "long").ifNotExist().create();
    schema.edgeLabel("aTOa").link(defaultVL, defaultVL).properties("gremlin.partitionGraphStrategy.partition").nullableKeys("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.edgeLabel("aTOb").link(defaultVL, defaultVL).properties("gremlin.partitionGraphStrategy.partition").nullableKeys("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.edgeLabel("bTOc").link(defaultVL, defaultVL).properties("gremlin.partitionGraphStrategy.partition").nullableKeys("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.edgeLabel("aTOc").link(defaultVL, defaultVL).properties("gremlin.partitionGraphStrategy.partition").nullableKeys("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.edgeLabel("connectsTo").link(defaultVL, defaultVL).properties("gremlin.partitionGraphStrategy.partition", "every").nullableKeys("gremlin.partitionGraphStrategy.partition", "every").ifNotExist().create();
    schema.edgeLabel("relatesTo").link(defaultVL, defaultVL).properties("gremlin.partitionGraphStrategy.partition", "every").nullableKeys("gremlin.partitionGraphStrategy.partition", "every").ifNotExist().create();
    schema.edgeLabel("test").link(defaultVL, defaultVL).properties("test", "xxx", "yyy").nullableKeys("test", "xxx", "yyy").ifNotExist().create();
    schema.edgeLabel("friend").link(defaultVL, defaultVL).properties("name", "location", "status", "uuid", "weight", "acl", "bloop").nullableKeys("name", "location", "status", "uuid", "weight", "acl", "bloop").ifNotExist().create();
    schema.edgeLabel("pets").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("walks").link(defaultVL, defaultVL).properties("location").nullableKeys("location").ifNotExist().create();
    schema.edgeLabel("livesWith").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("friends").link(defaultVL, defaultVL).properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.edgeLabel("collaborator").link(defaultVL, defaultVL).properties("location").nullableKeys("location").ifNotExist().create();
    schema.edgeLabel("hate").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("hates").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("test1").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("link").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("test2").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("test3").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("l").link(defaultVL, defaultVL).properties("name").nullableKeys("name").ifNotExist().create();
    schema.edgeLabel("CONTROL").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("SELFLOOP").link(defaultVL, defaultVL).ifNotExist().create();
    schema.edgeLabel("edge").link(defaultVL, defaultVL).properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.edgeLabel("next").link(defaultVL, defaultVL).ifNotExist().create();
    schema.indexLabel("selfByName").onE("self").by("name").ifNotExist().create();
    schema.indexLabel("selfBy__id").onE("self").by("__id").ifNotExist().create();
    schema.indexLabel("selfBySome").onE("self").by("some").ifNotExist().create();
    schema.indexLabel("selfByThis").onV(defaultVL).by("this").ifNotExist().create();
    schema.indexLabel("selfByAny").onV(defaultVL).by("any").ifNotExist().create();
    schema.indexLabel("selfByGremlinPartition").onV(defaultVL).by("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.indexLabel("aTOaByGremlinPartition").onE("aTOa").by("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.indexLabel("aTOcByGremlinPartition").onE("aTOc").by("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.indexLabel("bTOcByGremlinPartition").onE("bTOc").by("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)65 Id (com.baidu.hugegraph.backend.id.Id)30 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)9 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)8 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)7 ArrayList (java.util.ArrayList)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)4 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)4 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)4 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)4 Query (com.baidu.hugegraph.backend.query.Query)4 SchemaJob (com.baidu.hugegraph.job.schema.SchemaJob)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4