Search in sources :

Example 11 with IndexLabel

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

the class IndexLabelCoreTest method testAppendIndexLabelWithUserdata.

@Test
public void testAppendIndexLabelWithUserdata() {
    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).create();
    Assert.assertEquals(2, personByName.userdata().size());
    Assert.assertEquals(0, personByName.userdata().get("min"));
    personByName = schema.indexLabel("personByName").userdata("min", 1).userdata("max", 100).append();
    Assert.assertEquals(3, personByName.userdata().size());
    Assert.assertEquals(1, personByName.userdata().get("min"));
    Assert.assertEquals(100, personByName.userdata().get("max"));
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 12 with IndexLabel

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

the class IndexLabelCoreTest method testEliminateIndexLabelWithUserdata.

@Test
public void testEliminateIndexLabelWithUserdata() {
    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"));
    personByName = schema.indexLabel("personByName").userdata("max", "").eliminate();
    Assert.assertEquals(2, personByName.userdata().size());
    Assert.assertEquals(0, personByName.userdata().get("min"));
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 13 with IndexLabel

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

the class IndexLabelCoreTest method testAddIndexLabelOfVertex.

@Test
public void testAddIndexLabelOfVertex() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.propertyKey("born").asDate().ifNotExist().create();
    schema.propertyKey("fans").asLong().ifNotExist().create();
    schema.propertyKey("height").asFloat().ifNotExist().create();
    schema.propertyKey("idNo").asText().ifNotExist().create();
    schema.propertyKey("category").asText().valueSet().ifNotExist().create();
    schema.propertyKey("score").asInt().valueSet().ifNotExist().create();
    schema.vertexLabel("person").properties("id", "name", "age", "city", "born", "tags", "category", "score", "fans", "height", "weight", "idNo").primaryKeys("id").create();
    schema.indexLabel("personByName").onV("person").secondary().by("name").create();
    schema.indexLabel("personByCity").onV("person").search().by("city").create();
    schema.indexLabel("personByAge").onV("person").range().by("age").create();
    schema.indexLabel("personByBorn").onV("person").range().by("born").create();
    schema.indexLabel("personByFans").onV("person").range().by("fans").create();
    schema.indexLabel("personByHeight").onV("person").range().by("height").create();
    schema.indexLabel("personByWeight").onV("person").range().by("weight").create();
    schema.indexLabel("personByIdNo").onV("person").unique().by("idNo").create();
    schema.indexLabel("personByTags").onV("person").secondary().by("tags").create();
    schema.indexLabel("personByCategory").onV("person").search().by("category").create();
    schema.indexLabel("personByScore").onV("person").secondary().by("score").create();
    VertexLabel person = schema.getVertexLabel("person");
    IndexLabel personByName = schema.getIndexLabel("personByName");
    IndexLabel personByCity = schema.getIndexLabel("personByCity");
    IndexLabel personByAge = schema.getIndexLabel("personByAge");
    IndexLabel personByBorn = schema.getIndexLabel("personByBorn");
    IndexLabel personByFans = schema.getIndexLabel("personByFans");
    IndexLabel personByHeight = schema.getIndexLabel("personByHeight");
    IndexLabel personByWeight = schema.getIndexLabel("personByWeight");
    IndexLabel personByIdNo = schema.getIndexLabel("personByIdNo");
    IndexLabel personByTags = schema.getIndexLabel("personByTags");
    IndexLabel personByCategory = schema.getIndexLabel("personByCategory");
    IndexLabel personByScore = schema.getIndexLabel("personByScore");
    Assert.assertNotNull(personByName);
    Assert.assertNotNull(personByCity);
    Assert.assertNotNull(personByAge);
    Assert.assertNotNull(personByBorn);
    Assert.assertNotNull(personByFans);
    Assert.assertNotNull(personByHeight);
    Assert.assertNotNull(personByWeight);
    Assert.assertNotNull(personByIdNo);
    Assert.assertNotNull(personByTags);
    Assert.assertNotNull(personByCategory);
    Assert.assertEquals(11, person.indexLabels().size());
    assertContainsIl(person.indexLabels(), "personByName", "personByCity", "personByAge", "personByBorn", "personByFans", "personByHeight", "personByWeight", "personByIdNo", "personByTags", "personByCategory", "personByScore");
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByName.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByCity.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByAge.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByBorn.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByFans.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByHeight.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByWeight.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByIdNo.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByTags.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByCategory.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByScore.baseType());
    assertVLEqual("person", personByName.baseValue());
    assertVLEqual("person", personByCity.baseValue());
    assertVLEqual("person", personByAge.baseValue());
    assertVLEqual("person", personByBorn.baseValue());
    assertVLEqual("person", personByFans.baseValue());
    assertVLEqual("person", personByHeight.baseValue());
    assertVLEqual("person", personByWeight.baseValue());
    assertVLEqual("person", personByIdNo.baseValue());
    assertVLEqual("person", personByTags.baseValue());
    assertVLEqual("person", personByCategory.baseValue());
    assertVLEqual("person", personByScore.baseValue());
    Assert.assertEquals(IndexType.SECONDARY, personByName.indexType());
    Assert.assertEquals(IndexType.SEARCH, personByCity.indexType());
    Assert.assertEquals(IndexType.RANGE_INT, personByAge.indexType());
    Assert.assertEquals(IndexType.RANGE_LONG, personByBorn.indexType());
    Assert.assertEquals(IndexType.RANGE_LONG, personByFans.indexType());
    Assert.assertEquals(IndexType.RANGE_FLOAT, personByHeight.indexType());
    Assert.assertEquals(IndexType.RANGE_DOUBLE, personByWeight.indexType());
    Assert.assertEquals(IndexType.UNIQUE, personByIdNo.indexType());
    Assert.assertEquals(IndexType.SECONDARY, personByTags.indexType());
    Assert.assertEquals(IndexType.SEARCH, personByCategory.indexType());
    Assert.assertEquals(IndexType.SECONDARY, personByScore.indexType());
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 14 with IndexLabel

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

the class IndexLabelAPI method get.

@GET
@Timed
@Path("{name}")
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=index_label_read" })
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("name") String name) {
    LOG.debug("Graph [{}] get index label by name '{}'", graph, name);
    HugeGraph g = graph(manager, graph);
    IndexLabel indexLabel = g.schema().getIndexLabel(name);
    return manager.serializer(g).writeIndexlabel(mapIndexLabel(indexLabel));
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 15 with IndexLabel

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

the class IndexLabelAPI method update.

@PUT
@Timed
@Path("{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("name") String name, @QueryParam("action") String action, IndexLabelAPI.JsonIndexLabel jsonIndexLabel) {
    LOG.debug("Graph [{}] {} index label: {}", graph, action, jsonIndexLabel);
    checkUpdatingBody(jsonIndexLabel);
    E.checkArgument(name.equals(jsonIndexLabel.name), "The name in url(%s) and body(%s) are different", name, jsonIndexLabel.name);
    // Parse action parameter
    boolean append = checkAndParseAction(action);
    HugeGraph g = graph(manager, graph);
    IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
    IndexLabel indexLabel = append ? builder.append() : builder.eliminate();
    return manager.serializer(g).writeIndexlabel(mapIndexLabel(indexLabel));
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) PUT(jakarta.ws.rs.PUT)

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