Search in sources :

Example 51 with IndexLabel

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

the class IndexLabelCoreTest method testAddIndexLabelWithUserdata.

@Test
public void testAddIndexLabelWithUserdata() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("id", "name", "age", "city").primaryKeys("id").create();
    IndexLabel personByName = schema.indexLabel("personByName").onV("person").secondary().by("name").userdata("min", 0).userdata("max", 100).create();
    Assert.assertEquals(3, personByName.userdata().size());
    Assert.assertEquals(0, personByName.userdata().get("min"));
    Assert.assertEquals(100, personByName.userdata().get("max"));
    IndexLabel personByAge = schema.indexLabel("personByAge").onV("person").range().by("age").userdata("length", 15).userdata("length", 18).create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, personByAge.userdata().size());
    Assert.assertEquals(18, personByAge.userdata().get("length"));
    List<Object> datas = ImmutableList.of("Beijing", "Shanghai");
    IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").secondary().by("city").userdata("range", datas).create();
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals(datas, personByCity.userdata().get("range"));
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 52 with IndexLabel

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

the class IndexLabelCoreTest method testCreateTime.

@Test
public void testCreateTime() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("id", "name", "age", "city").primaryKeys("id").create();
    IndexLabel personByName = schema.indexLabel("personByName").onV("person").secondary().by("name").create();
    Date createTime = (Date) personByName.userdata().get(Userdata.CREATE_TIME);
    Date now = DateUtil.now();
    Assert.assertFalse(createTime.after(now));
    personByName = schema.getIndexLabel("personByName");
    createTime = (Date) personByName.userdata().get(Userdata.CREATE_TIME);
    Assert.assertFalse(createTime.after(now));
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 53 with IndexLabel

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

the class FakeObjects method newIndexLabel.

public IndexLabel newIndexLabel(Id id, String name, HugeType baseType, Id baseValue, IndexType indexType, Id... fields) {
    IndexLabel schema = new IndexLabel(this.graph, id, name);
    schema.baseType(baseType);
    schema.baseValue(baseValue);
    schema.indexType(indexType);
    schema.indexFields(fields);
    Mockito.when(this.graph.indexLabel(id)).thenReturn(schema);
    return schema;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel)

Aggregations

IndexLabel (com.baidu.hugegraph.schema.IndexLabel)53 Id (com.baidu.hugegraph.backend.id.Id)24 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)8 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)8 Test (org.junit.Test)8 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)7 HugeGraph (com.baidu.hugegraph.HugeGraph)5 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)5 HugeType (com.baidu.hugegraph.type.HugeType)5 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)4 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)4 LockUtil (com.baidu.hugegraph.util.LockUtil)4 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)3 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)3 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)3 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)3 Condition (com.baidu.hugegraph.backend.query.Condition)3