Search in sources :

Example 26 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class ShortestPathApiTest method testShortestPath.

@Test
public void testShortestPath() {
    Path path = shortestPathAPI.get(1, 6, Direction.BOTH, null, 6, -1L, 0L, -1L);
    Assert.assertEquals(4, path.size());
    Assert.assertEquals(ImmutableList.of(1, 10, 11, 6), path.objects());
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Test(org.junit.Test)

Example 27 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class ShortestPathApiTest method testShortestPathWithMaxDepth.

@Test
public void testShortestPathWithMaxDepth() {
    Path path = shortestPathAPI.get(14, 6, Direction.BOTH, null, 4, 5L, 0L, 19L);
    Assert.assertEquals(5, path.size());
    Assert.assertEquals(ImmutableList.of(14, 7, 8, 9, 6), path.objects());
    path = shortestPathAPI.get(14, 6, Direction.BOTH, null, 3, 5L, 0L, 19L);
    Assert.assertEquals(0, path.size());
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Test(org.junit.Test)

Example 28 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class ShortestPathApiTest method testShortestPathWithDegree.

@Test
public void testShortestPathWithDegree() {
    Path path = shortestPathAPI.get(1, 6, Direction.OUT, null, 6, 1L, 0L, -1L);
    /*
         * Following results can be guaranteed in RocksDB backend,
         * but different results exist in table type backend(like Cassandra).
         */
    Assert.assertEquals(6, path.size());
    Assert.assertEquals(ImmutableList.of(1, 2, 3, 4, 5, 6), path.objects());
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Test(org.junit.Test)

Example 29 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class GremlinApiTest method testAttachedManager.

@Test
public void testAttachedManager() {
    GremlinRequest request = new GremlinRequest("g.V()");
    ResultSet resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    Iterator<Result> results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Vertex.class, object.getClass());
        Vertex vertex = (Vertex) object;
        Assert.assertNotNull(Whitebox.getInternalState(vertex, "manager"));
    }
    request = new GremlinRequest("g.E()");
    resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Edge.class, object.getClass());
        Edge edge = (Edge) object;
        Assert.assertNotNull(Whitebox.getInternalState(edge, "manager"));
    }
    request = new GremlinRequest("g.V().outE().path()");
    resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Path.class, object.getClass());
        Path path = (Path) object;
        Assert.assertNotNull(path.objects());
        for (Object pathObject : path.objects()) {
            Assert.assertTrue(pathObject instanceof GraphAttachable);
            Assert.assertNotNull(Whitebox.getInternalState(pathObject, "manager"));
        }
        Assert.assertNull(path.crosspoint());
    }
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphAttachable(com.baidu.hugegraph.structure.constant.GraphAttachable) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) GremlinRequest(com.baidu.hugegraph.api.gremlin.GremlinRequest) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result) Test(org.junit.Test)

Example 30 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class PathDeserializer method deserialize.

@Override
public Path deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
    JsonNode node = parser.getCodec().readTree(parser);
    Path path = new Path();
    // Parse node 'labels'
    JsonNode labelsNode = node.get("labels");
    if (labelsNode != null) {
        if (labelsNode.getNodeType() != JsonNodeType.ARRAY) {
            throw InvalidResponseException.expectField("labels", node);
        }
        Object labels = JsonUtil.convertValue(labelsNode, Object.class);
        ((List<?>) labels).forEach(path::labels);
    }
    // Parse node 'objects'
    JsonNode objectsNode = node.get("objects");
    if (objectsNode == null || objectsNode.getNodeType() != JsonNodeType.ARRAY) {
        throw InvalidResponseException.expectField("objects", node);
    }
    Iterator<JsonNode> objects = objectsNode.elements();
    while (objects.hasNext()) {
        JsonNode objectNode = objects.next();
        JsonNode typeNode = objectNode.get("type");
        Object object;
        if (typeNode != null) {
            object = parseTypedNode(objectNode, typeNode);
        } else {
            object = JsonUtil.convertValue(objectNode, Object.class);
        }
        path.objects(object);
    }
    // Parse node 'crosspoint'
    JsonNode crosspointNode = node.get("crosspoint");
    if (crosspointNode != null) {
        Object object = JsonUtil.convertValue(crosspointNode, Object.class);
        path.crosspoint(object);
    }
    return path;
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List)

Aggregations

Path (com.baidu.hugegraph.structure.graph.Path)30 Test (org.junit.Test)21 Vertex (com.baidu.hugegraph.structure.graph.Vertex)11 Edge (com.baidu.hugegraph.structure.graph.Edge)9 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)7 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)6 Result (com.baidu.hugegraph.structure.gremlin.Result)6 HugeClient (com.baidu.hugegraph.driver.HugeClient)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)4 ArrayList (java.util.ArrayList)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TableView (com.baidu.hugegraph.entity.query.TableView)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3 HashMap (java.util.HashMap)3 GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)2 Type (com.baidu.hugegraph.entity.query.GremlinResult.Type)2 JsonView (com.baidu.hugegraph.entity.query.JsonView)2 RestResult (com.baidu.hugegraph.rest.RestResult)2