Search in sources :

Example 51 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class TaskApiTest method testListAll.

@Test
public void testListAll() {
    IndexLabel personByCity = schema().getIndexLabel("personByCity");
    IndexLabel personByAge = schema().getIndexLabel("personByAge");
    IndexLabel knowsByDate = schema().getIndexLabel("knowsByDate");
    IndexLabel createdByDate = schema().getIndexLabel("createdByDate");
    Set<Long> taskIds = new HashSet<>();
    taskIds.add(rebuildAPI.rebuild(personByCity));
    taskIds.add(rebuildAPI.rebuild(personByAge));
    taskIds.add(rebuildAPI.rebuild(knowsByDate));
    taskIds.add(rebuildAPI.rebuild(createdByDate));
    List<Task> tasks = taskAPI.list(null, -1);
    Assert.assertEquals(4, tasks.size());
    Set<Long> listedTaskIds = new HashSet<>();
    for (Task task : tasks) {
        listedTaskIds.add(task.id());
    }
    Assert.assertEquals(taskIds.size(), listedTaskIds.size());
    Assert.assertTrue(taskIds.containsAll(listedTaskIds));
    taskIds.forEach(BaseApiTest::waitUntilTaskCompleted);
    taskIds.forEach(id -> taskAPI.delete(id));
    tasks = taskAPI.list(null, -1);
    Assert.assertEquals(0, tasks.size());
}
Also used : Task(com.baidu.hugegraph.structure.Task) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class IndexLabelApiTest method testAddIndexLabelWithRebuildFalse.

@Test
public void testAddIndexLabelWithRebuildFalse() {
    Vertex vertex = new Vertex("person");
    vertex.property("name", "James");
    vertex.property("city", "Beijing");
    vertex.property("age", 19);
    vertex = vertexAPI.create(vertex);
    IndexLabel personByAge = schema().indexLabel("personByAge").onV("person").by("city").secondary().rebuild(false).build();
    IndexLabel.IndexLabelWithTask il = indexLabelAPI.create(personByAge);
    IndexLabel created = il.indexLabel();
    Assert.assertEquals(personByAge.name(), created.name());
    Assert.assertEquals(personByAge.baseType(), created.baseType());
    Assert.assertEquals(personByAge.baseValue(), created.baseValue());
    Assert.assertEquals(personByAge.indexType(), created.indexType());
    Assert.assertEquals(Task.TASK_ID_NULL, il.taskId());
    Map<String, Object> properties = ImmutableMap.of("city", "Beijing");
    List<Vertex> vertices = vertexAPI.list("person", properties, 0, null, 10).results();
    Assert.assertEquals(0, vertices.size());
    long taskId = rebuildAPI.rebuild(personByAge);
    waitUntilTaskCompleted(taskId);
    vertices = vertexAPI.list("person", properties, 0, null, 10).results();
    Assert.assertEquals(1, vertices.size());
    Assert.assertEquals(vertex, vertices.get(0));
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 53 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class IndexLabelApiTest method testGet.

@Test
public void testGet() {
    IndexLabel indexLabel1 = schema().indexLabel("personByAge").onV("person").by("age").range().build();
    indexLabel1 = indexLabelAPI.create(indexLabel1).indexLabel();
    IndexLabel indexLabel2 = indexLabelAPI.get("personByAge");
    Assert.assertEquals(indexLabel1.name(), indexLabel2.name());
    Assert.assertEquals(indexLabel1.baseType(), indexLabel2.baseType());
    Assert.assertEquals(indexLabel1.baseValue(), indexLabel2.baseValue());
    Assert.assertEquals(indexLabel1.indexType(), indexLabel2.indexType());
    Assert.assertEquals(indexLabel1.indexFields(), indexLabel2.indexFields());
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 54 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class JobApiTest method testRebuildIndexLabel.

@Test
public void testRebuildIndexLabel() {
    IndexLabel personByCity = schema().getIndexLabel("personByAge");
    long taskId = rebuildAPI.rebuild(personByCity);
    Task task = taskAPI.get(taskId);
    Assert.assertNotNull(task);
    Assert.assertEquals(taskId, task.id());
    waitUntilTaskCompleted(taskId);
}
Also used : Task(com.baidu.hugegraph.structure.Task) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 55 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class IndexLabelAPI method checkCreateOrUpdate.

@Override
protected Object checkCreateOrUpdate(SchemaElement schemaElement) {
    IndexLabel indexLabel = (IndexLabel) schemaElement;
    if (indexLabel.indexType() == IndexType.SHARD) {
        this.client.checkApiVersion("0.43", "shard index");
    } else if (indexLabel.indexType() == IndexType.UNIQUE) {
        this.client.checkApiVersion("0.44", "unique index");
    }
    IndexLabel il = indexLabel;
    if (this.client.apiVersionLt("0.50")) {
        E.checkArgument(indexLabel.userdata() == null || indexLabel.userdata().isEmpty(), "Not support userdata of index label until api " + "version 0.50");
        E.checkArgument(indexLabel.rebuild(), "Not support rebuild of index label until api " + "version 0.57");
        il = indexLabel.switchV49();
    } else if (this.client.apiVersionLt("0.57")) {
        E.checkArgument(indexLabel.rebuild(), "Not support rebuild of index label until api " + "version 0.57");
        il = indexLabel.switchV56();
    }
    return il;
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel)

Aggregations

IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)56 Test (org.junit.Test)34 HugeClient (com.baidu.hugegraph.driver.HugeClient)14 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)11 ArrayList (java.util.ArrayList)10 ServerException (com.baidu.hugegraph.exception.ServerException)9 ExternalException (com.baidu.hugegraph.exception.ExternalException)8 Task (com.baidu.hugegraph.structure.Task)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)6 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)6 Date (java.util.Date)6 RestResult (com.baidu.hugegraph.rest.RestResult)4 HashSet (java.util.HashSet)4 SchemaType (com.baidu.hugegraph.entity.schema.SchemaType)2 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)2 TasksWithPage (com.baidu.hugegraph.api.task.TasksWithPage)1 Constant (com.baidu.hugegraph.common.Constant)1 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1