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"));
}
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"));
}
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());
}
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));
}
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));
}
Aggregations