Search in sources :

Example 6 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testEliminateEdgeLabelWithUserData.

@Test
public void testEliminateEdgeLabelWithUserData() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertEquals(3, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    Assert.assertEquals("picture2", write.userdata().get("icon"));
    String time = (String) write.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    write = schema.edgeLabel("write").userdata("icon", "").eliminate();
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    time = (String) write.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 7 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testListByNames.

@Test
public void testListByNames() {
    SchemaManager schema = schema();
    EdgeLabel father = schema.edgeLabel("father").link("person", "person").create();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").create();
    List<EdgeLabel> edgeLabels;
    edgeLabels = schema.getEdgeLabels(ImmutableList.of("father"));
    Assert.assertEquals(1, edgeLabels.size());
    assertContains(edgeLabels, father);
    edgeLabels = schema.getEdgeLabels(ImmutableList.of("write"));
    Assert.assertEquals(1, edgeLabels.size());
    assertContains(edgeLabels, write);
    edgeLabels = schema.getEdgeLabels(ImmutableList.of("father", "write"));
    Assert.assertEquals(2, edgeLabels.size());
    assertContains(edgeLabels, father);
    assertContains(edgeLabels, write);
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 8 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testResetEdgeLabelId.

@Test
public void testResetEdgeLabelId() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertTrue(write.id() > 0);
    write.resetId();
    Assert.assertEquals(0L, write.id());
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 9 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class PersonalRankApiTest method initPersonalRankGraph.

@BeforeClass
public static void initPersonalRankGraph() {
    GraphManager graph = graph();
    SchemaManager schema = schema();
    schema.propertyKey("name").asText().ifNotExist().create();
    schema.vertexLabel("person").properties("name").useCustomizeStringId().ifNotExist().create();
    schema.vertexLabel("movie").properties("name").useCustomizeStringId().ifNotExist().create();
    schema.edgeLabel("like").sourceLabel("person").targetLabel("movie").ifNotExist().create();
    Vertex A = graph.addVertex(T.label, "person", T.id, "A", "name", "A");
    Vertex B = graph.addVertex(T.label, "person", T.id, "B", "name", "B");
    Vertex C = graph.addVertex(T.label, "person", T.id, "C", "name", "C");
    Vertex a = graph.addVertex(T.label, "movie", T.id, "a", "name", "a");
    Vertex b = graph.addVertex(T.label, "movie", T.id, "b", "name", "b");
    Vertex c = graph.addVertex(T.label, "movie", T.id, "c", "name", "c");
    Vertex d = graph.addVertex(T.label, "movie", T.id, "d", "name", "d");
    A.addEdge("like", a);
    A.addEdge("like", c);
    B.addEdge("like", a);
    B.addEdge("like", b);
    B.addEdge("like", c);
    B.addEdge("like", d);
    C.addEdge("like", c);
    C.addEdge("like", d);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) BeforeClass(org.junit.BeforeClass)

Example 10 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class IndexLabelTest method testAppendIndexLabelWithUserData.

@Test
public void testAppendIndexLabelWithUserData() {
    SchemaManager schema = schema();
    BaseFuncTest.initVertexLabel();
    IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create();
    Assert.assertEquals(1, personByCity.userdata().size());
    String time = (String) personByCity.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    personByCity = schema.indexLabel("personByCity").userdata("type", "secondary").append();
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals("secondary", personByCity.userdata().get("type"));
    time = (String) personByCity.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SchemaManager (com.baidu.hugegraph.driver.SchemaManager)61 Test (org.junit.Test)39 Vertex (com.baidu.hugegraph.structure.graph.Vertex)18 Date (java.util.Date)14 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)11 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 BeforeClass (org.junit.BeforeClass)8 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)6 Edge (com.baidu.hugegraph.structure.graph.Edge)4 ArrayList (java.util.ArrayList)3 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)2 Task (com.baidu.hugegraph.structure.Task)2 Result (com.baidu.hugegraph.structure.gremlin.Result)2 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)2 BaseClientTest (com.baidu.hugegraph.BaseClientTest)1 GremlinManager (com.baidu.hugegraph.driver.GremlinManager)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1