Search in sources :

Example 11 with SchemaManager

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

the class IndexLabelTest method testAddIndexLabelAsync.

@Test
public void testAddIndexLabelAsync() {
    SchemaManager schema = schema();
    schema.vertexLabel("player").properties("name", "age").create();
    IndexLabel playerByName = schema.indexLabel("playerByName").onV("player").by("name").secondary().build();
    long task = schema.addIndexLabelAsync(playerByName);
    waitUntilTaskCompleted(task);
    playerByName = schema.getIndexLabel(playerByName.name());
    Assert.assertNotNull(playerByName);
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 12 with SchemaManager

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

the class IndexLabelTest method testEliminateIndexLabelWithUserData.

@Test
public void testEliminateIndexLabelWithUserData() {
    SchemaManager schema = schema();
    BaseFuncTest.initVertexLabel();
    IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").by("city").secondary().userdata("type", "secondary").userdata("icon", "picture").ifNotExist().create();
    Assert.assertEquals(3, personByCity.userdata().size());
    Assert.assertEquals("secondary", personByCity.userdata().get("type"));
    Assert.assertEquals("picture", personByCity.userdata().get("icon"));
    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").eliminate();
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals("picture", personByCity.userdata().get("icon"));
    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)

Example 13 with SchemaManager

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

the class IndexLabelTest method testAddIndexLabelWithUserData.

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

Example 14 with SchemaManager

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

the class IndexLabelTest method testRemoveIndexLabelAsync.

@Test
public void testRemoveIndexLabelAsync() {
    SchemaManager schema = schema();
    schema.vertexLabel("player").properties("name", "age").create();
    IndexLabel playerByName = schema.indexLabel("playerByName").onV("player").by("name").secondary().create();
    Assert.assertNotNull(playerByName);
    // Remove index label async
    schema.removeIndexLabelAsync("playerByName");
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 15 with SchemaManager

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

the class PropertyKeyTest method testListByNames.

@Test
public void testListByNames() {
    SchemaManager schema = schema();
    PropertyKey age = schema.propertyKey("age").create();
    PropertyKey id = schema.propertyKey("id").create();
    List<PropertyKey> propertyKeys;
    propertyKeys = schema.getPropertyKeys(ImmutableList.of("age"));
    Assert.assertEquals(1, propertyKeys.size());
    assertContains(propertyKeys, age);
    propertyKeys = schema.getPropertyKeys(ImmutableList.of("id"));
    Assert.assertEquals(1, propertyKeys.size());
    assertContains(propertyKeys, id);
    propertyKeys = schema.getPropertyKeys(ImmutableList.of("age", "id"));
    Assert.assertEquals(2, propertyKeys.size());
    assertContains(propertyKeys, age);
    assertContains(propertyKeys, id);
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) 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