use of com.baidu.hugegraph.schema.SchemaManager 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.SchemaManager in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testDuplicateIndexLabelWithDifferentProperties.
@Test
public void testDuplicateIndexLabelWithDifferentProperties() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.edgeLabel("friend").link("person", "person").properties("time").ifNotExist().create();
schema.indexLabel("index4Person").onV("person").by("age", "city").secondary().ifNotExist().create();
Assert.assertThrows(ExistedException.class, () -> {
schema.indexLabel("index4Person").onV("person").by(// remove city
"age").secondary().checkExist(false).create();
});
Assert.assertThrows(ExistedException.class, () -> {
schema.indexLabel("index4Person").onE(// not on person
"friend").by("age").secondary().checkExist(false).create();
});
schema.indexLabel("index4Friend").onE("friend").search().by("time").ifNotExist().create();
Assert.assertThrows(ExistedException.class, () -> {
schema.indexLabel("index4Friend").onE("friend").by("time").checkExist(false).create();
});
schema.indexLabel("ageIndex4Person").onV("person").by("age").range().ifNotExist().create();
Assert.assertThrows(ExistedException.class, () -> {
schema.indexLabel("ageIndex4Person").onV("person").by("age").secondary().ifNotExist().create();
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testRemoveIndexLabelOfEdge.
@Test
public void testRemoveIndexLabelOfEdge() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
schema.vertexLabel("book").properties("name").primaryKeys("name").create();
schema.edgeLabel("authored").singleTime().link("author", "book").properties("contribution").create();
Vertex james = graph().addVertex(T.label, "author", "id", 1, "name", "James Gosling");
Vertex java1 = graph().addVertex(T.label, "book", "name", "java-1");
schema.indexLabel("authoredByContri").onE("authored").secondary().by("contribution").create();
EdgeLabel authored = schema.getEdgeLabel("authored");
Assert.assertEquals(1, authored.indexLabels().size());
assertContainsIl(authored.indexLabels(), "authoredByContri");
james.addEdge("authored", java1, "contribution", "test");
graph().tx().commit();
Edge edge = graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
Assert.assertNotNull(edge);
schema.indexLabel("authoredByContri").remove();
Assert.assertThrows(NotFoundException.class, () -> {
schema.getIndexLabel("authoredByContri");
});
/*
* Should not expect that schemalabel previously constructed can be
* dynamically modified with index label operation
*/
authored = schema.getEdgeLabel("authored");
Assert.assertEquals(0, authored.indexLabels().size());
Assert.assertThrows(NoIndexException.class, () -> {
graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testAddIndexLabelWithInvalidFieldsForAggregateProperty.
@Test
public void testAddIndexLabelWithInvalidFieldsForAggregateProperty() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.propertyKey("sumProp").asLong().valueSingle().calcSum().ifNotExist().create();
schema.vertexLabel("author").properties("id", "name", "age", "sumProp").primaryKeys("id").create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.indexLabel("authorBySumProp").onV("author").by("sumProp").secondary().ifNotExist().create();
}, e -> {
Assert.assertContains("The aggregate type SUM is not indexable", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.indexLabel("authorBySumProp").onV("author").by("sumProp").range().ifNotExist().create();
}, e -> {
Assert.assertContains("The aggregate type SUM is not indexable", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.indexLabel("authorBySumProp").onV("author").by("sumProp").shard().ifNotExist().create();
}, e -> {
Assert.assertContains("The aggregate type SUM is not indexable", e.getMessage());
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testUpdateIndexLabelWithoutUserdata.
@Test
public void testUpdateIndexLabelWithoutUserdata() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("id", "name", "age", "city").primaryKeys("id").create();
schema.vertexLabel("software").properties("id", "name").primaryKeys("id").create();
schema.indexLabel("personByName").onV("person").secondary().by("name").userdata("min", 0).userdata("max", 100).create();
Assert.assertThrows(HugeException.class, () -> {
schema.indexLabel("personByName").onV("software").append();
});
Assert.assertThrows(HugeException.class, () -> {
schema.indexLabel("personByName").range().append();
});
Assert.assertThrows(HugeException.class, () -> {
schema.indexLabel("personByName").by("age").append();
});
Assert.assertThrows(HugeException.class, () -> {
schema.indexLabel("personByName").onV("software").eliminate();
});
Assert.assertThrows(HugeException.class, () -> {
schema.indexLabel("personByName").range().eliminate();
});
Assert.assertThrows(HugeException.class, () -> {
schema.indexLabel("personByName").by("age").eliminate();
});
}
Aggregations