Search in sources :

Example 26 with Edge

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

the class EdgeTest method testLinkedVertex.

@Test
public void testLinkedVertex() {
    Object peterId = getVertexId("person", "name", "peter");
    Object lopId = getVertexId("software", "name", "lop");
    Edge created = graph().addEdge(peterId, "created", lopId, "date", "2017-03-24");
    Assert.assertTrue(created.linkedVertex(peterId));
    Assert.assertTrue(created.linkedVertex(lopId));
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 27 with Edge

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

the class EdgeTest method testGetEdgesByLabelAndPropertiesWithRangeCondition.

@Test
public void testGetEdgesByLabelAndPropertiesWithRangeCondition() throws ParseException {
    schema().indexLabel("knowsByDate").range().onE("knows").by("date").create();
    schema().indexLabel("createdByDate").range().onE("created").by("date").create();
    BaseClientTest.initEdge();
    Date expected = DateUtil.parse("2014-01-10");
    Date expected2 = DateUtil.parse("2016-01-10");
    Map<String, Object> properties = ImmutableMap.of("date", "P.eq(\"2014-1-10\")");
    List<Edge> edges = graph().listEdges("created", properties);
    Date time;
    Assert.assertEquals(1, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("created", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertEquals(expected.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.gt(\"2014-1-10\")");
    edges = graph().listEdges("created", properties);
    Assert.assertEquals(3, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("created", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertGt(expected.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.gte(\"2014-1-10\")");
    edges = graph().listEdges("created", properties);
    Assert.assertEquals(4, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("created", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertGte(expected.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.lt(\"2014-1-10\")");
    edges = graph().listEdges(null, properties);
    Assert.assertEquals(2, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("knows", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertLt(expected.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.lte(\"2014-1-10\")");
    edges = graph().listEdges(null, properties);
    Assert.assertEquals(3, edges.size());
    for (Edge e : edges) {
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertLte(expected.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.between(\"2014-1-10\",\"2016-1-10\")");
    edges = graph().listEdges(null, properties);
    Assert.assertEquals(2, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("created", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertGte(expected.getTime(), time.getTime());
        Assert.assertLt(expected2.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.inside(\"2014-1-10\",\"2016-1-10\")");
    edges = graph().listEdges(null, properties);
    Assert.assertEquals(1, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("created", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertGt(expected.getTime(), time.getTime());
        Assert.assertLt(expected2.getTime(), time.getTime());
    }
    properties = ImmutableMap.of("date", "P.within(\"2014-1-10\",\"2016-1-10\")");
    edges = graph().listEdges(null, properties);
    Assert.assertEquals(2, edges.size());
    for (Edge e : edges) {
        Assert.assertEquals("created", e.label());
        time = DateUtil.parse((String) e.property("date"));
        Assert.assertGte(expected.getTime(), time.getTime());
        Assert.assertLte(expected2.getTime(), time.getTime());
    }
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Date(java.util.Date) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 28 with Edge

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

the class EdgeTest method testAddEdgePropertyValueSetWithSameValue.

@Test
public void testAddEdgePropertyValueSetWithSameValue() {
    schema().propertyKey("time").asDate().valueSet().ifNotExist().create();
    schema().edgeLabel("created").properties("time").nullableKeys("time").append();
    Object peterId = getVertexId("person", "name", "peter");
    Object lopId = getVertexId("software", "name", "lop");
    Edge created = graph().addEdge(peterId, "created", lopId, "date", "2017-03-24", "time", "2012-10-10");
    Map<String, Object> props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"), "time", ImmutableList.of(Utils.formatDate("2012-10-10")));
    Assert.assertEquals(props, created.properties());
    created.property("time", "2012-10-10");
    props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"), "time", ImmutableList.of(Utils.formatDate("2012-10-10")));
    Assert.assertEquals(props, created.properties());
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 29 with Edge

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

the class EdgeTest method testRemoveEdgePropertyNotExist.

@Test
public void testRemoveEdgePropertyNotExist() {
    Object peterId = getVertexId("person", "name", "peter");
    Object lopId = getVertexId("software", "name", "lop");
    Edge created = graph().addEdge(peterId, "created", lopId, "date", "2017-03-24");
    Map<String, Object> props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"));
    Assert.assertEquals(props, created.properties());
    Assert.assertThrows(InvalidOperationException.class, () -> {
        created.removeProperty("not-exist");
    });
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 30 with Edge

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

the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyEliminate.

@Test
public void testEdgeBatchUpdateStrategyEliminate() {
    BatchEdgeRequest req = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
    List<Edge> edges = edgeAPI.update(req);
    assertBatchResponse(edges, "list");
    req = batchEdgeRequest("list", "old", "new", UpdateStrategy.ELIMINATE);
    edges = edgeAPI.update(req);
    assertBatchResponse(edges, "list", "old");
}
Also used : BatchEdgeRequest(com.baidu.hugegraph.structure.graph.BatchEdgeRequest) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (com.baidu.hugegraph.structure.graph.Edge)103 Test (org.junit.Test)73 Vertex (com.baidu.hugegraph.structure.graph.Vertex)33 ArrayList (java.util.ArrayList)22 BaseClientTest (com.baidu.hugegraph.BaseClientTest)20 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)12 HugeClient (com.baidu.hugegraph.driver.HugeClient)10 Path (com.baidu.hugegraph.structure.graph.Path)9 Result (com.baidu.hugegraph.structure.gremlin.Result)8 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)7 RestResult (com.baidu.hugegraph.rest.RestResult)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 GraphManager (com.baidu.hugegraph.driver.GraphManager)4 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 Edges (com.baidu.hugegraph.structure.graph.Edges)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3