Search in sources :

Example 26 with IndexLabel

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

the class IndexLabelApiTest method testCreate.

@Test
public void testCreate() {
    IndexLabel indexLabel = indexLabelAPI.create(fillIndexLabel.apply("personByAge")).indexLabel();
    Assert.assertEquals("personByAge", indexLabel.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel.baseType());
    Assert.assertEquals("person", indexLabel.baseValue());
    Assert.assertEquals(IndexType.RANGE, indexLabel.indexType());
    List<String> fields = ImmutableList.of("age");
    Assert.assertTrue(fields.size() == indexLabel.indexFields().size());
    Assert.assertTrue(fields.containsAll(indexLabel.indexFields()));
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 27 with IndexLabel

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

the class IndexLabelApiTest method testAddIndexLabelWithUserData.

@Test
public void testAddIndexLabelWithUserData() {
    IndexLabel personByAge = schema().indexLabel("personByAge").onV("person").by("age").range().userdata("min", 0).userdata("max", 100).build();
    personByAge = indexLabelAPI.create(personByAge).indexLabel();
    Assert.assertEquals(3, personByAge.userdata().size());
    Assert.assertEquals(0, personByAge.userdata().get("min"));
    Assert.assertEquals(100, personByAge.userdata().get("max"));
    String time = (String) personByAge.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    IndexLabel personByCity = schema().indexLabel("personByCity").onV("person").by("city").secondary().userdata("length", 15).userdata("length", 18).build();
    personByCity = indexLabelAPI.create(personByCity).indexLabel();
    // The same key user data will be overwritten
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals(18, personByCity.userdata().get("length"));
    time = (String) personByCity.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    IndexLabel bookByName = schema().indexLabel("bookByName").onV("book").by("name").secondary().userdata("option", ImmutableList.of("xx", "yy")).build();
    bookByName = indexLabelAPI.create(bookByName).indexLabel();
    Assert.assertEquals(2, bookByName.userdata().size());
    Assert.assertEquals(ImmutableList.of("xx", "yy"), bookByName.userdata().get("option"));
    time = (String) bookByName.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Date(java.util.Date) Test(org.junit.Test)

Example 28 with IndexLabel

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

the class IndexLabelApiTest method testAddIndexLabelWithUserDataWithApiVersion49.

@Test
public void testAddIndexLabelWithUserDataWithApiVersion49() {
    VersionUtil.Version originApiVersion = client().apiVersion();
    VersionUtil.Version apiVersion = VersionUtil.Version.of("0.49");
    client().apiVersion(apiVersion);
    IndexLabel personByAge = schema().indexLabel("personByAge").onV("person").by("age").range().build();
    personByAge = indexLabelAPI.create(personByAge).indexLabel();
    Assert.assertEquals(1, personByAge.userdata().size());
    IndexLabel personByAge1 = schema().indexLabel("personByAge1").onV("person").by("age").range().userdata("min", 0).userdata("max", 100).build();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        indexLabelAPI.create(personByAge1).indexLabel();
    }, (e) -> {
        String msg = "Not support userdata of index label until api " + "version 0.50";
        Assert.assertContains(msg, e.getMessage());
    });
    IndexLabel personByAge2 = schema().indexLabel("personByAge2").onV("person").by("age").userdata("min", 0).build();
    Assert.assertThrows(NotSupportException.class, () -> {
        indexLabelAPI.append(personByAge2);
    }, (e) -> {
        Assert.assertContains("action append on index label", e.getMessage());
    });
    IndexLabel personByAge3 = schema().indexLabel("personByAge3").onV("person").by("age").userdata("min", 0).build();
    Assert.assertThrows(NotSupportException.class, () -> {
        indexLabelAPI.eliminate(personByAge3);
    }, (e) -> {
        Assert.assertContains("action eliminate on index label", e.getMessage());
    });
    client().apiVersion(originApiVersion);
}
Also used : VersionUtil(com.baidu.hugegraph.util.VersionUtil) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 29 with IndexLabel

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

the class PropertyIndexService method checkConflict.

public ConflictStatus checkConflict(PropertyIndex entity, int connId) {
    HugeClient client = this.client(connId);
    String name = entity.getName();
    IndexLabel newIndexLabel = convert(entity, client);
    IndexLabel oldIndexLabel = convert(this.get(name, connId), client);
    if (oldIndexLabel == null) {
        return ConflictStatus.PASSED;
    } else if (isEqual(newIndexLabel, oldIndexLabel)) {
        return ConflictStatus.EXISTED;
    } else {
        return ConflictStatus.DUPNAME;
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel)

Example 30 with IndexLabel

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

the class PropertyIndexService method list.

public List<PropertyIndex> list(Collection<String> names, int connId, boolean emptyAsAll) {
    HugeClient client = this.client(connId);
    List<IndexLabel> indexLabels;
    if (CollectionUtils.isEmpty(names)) {
        if (emptyAsAll) {
            indexLabels = client.schema().getIndexLabels();
        } else {
            indexLabels = new ArrayList<>();
        }
    } else {
        indexLabels = client.schema().getIndexLabels(new ArrayList<>(names));
    }
    List<PropertyIndex> results = new ArrayList<>(indexLabels.size());
    indexLabels.forEach(indexLabel -> {
        results.add(convert(indexLabel));
    });
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

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