use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class TestGraph method initGratefulSchema.
@Watched
public void initGratefulSchema(IdStrategy idStrategy) {
SchemaManager schema = this.graph.schema();
schema.propertyKey("id").asInt().ifNotExist().create();
schema.propertyKey("weight").asInt().ifNotExist().create();
schema.propertyKey("name").ifNotExist().create();
schema.propertyKey("songType").asText().ifNotExist().create();
schema.propertyKey("performances").asInt().ifNotExist().create();
switch(idStrategy) {
case AUTOMATIC:
schema.vertexLabel("song").properties("id", "name", "songType", "performances").nullableKeys("id", "name", "songType", "performances").ifNotExist().create();
schema.vertexLabel("artist").properties("id", "name").nullableKeys("id", "name").ifNotExist().create();
break;
case CUSTOMIZE_STRING:
schema.vertexLabel("song").properties("id", "name", "songType", "performances").nullableKeys("id", "name", "songType", "performances").useCustomizeStringId().ifNotExist().create();
schema.vertexLabel("artist").properties("id", "name").nullableKeys("id", "name").useCustomizeStringId().ifNotExist().create();
break;
default:
throw new AssertionError(String.format("Id strategy must be customize or automatic"));
}
schema.edgeLabel("followedBy").link("song", "song").properties("weight").nullableKeys("weight").ifNotExist().create();
schema.edgeLabel("sungBy").link("song", "artist").ifNotExist().create();
schema.edgeLabel("writtenBy").link("song", "artist").ifNotExist().create();
schema.indexLabel("songByName").onV("song").by("name").ifNotExist().create();
schema.indexLabel("songBySongType").onV("song").by("songType").ifNotExist().create();
schema.indexLabel("songByPerf").onV("song").by("performances").ifNotExist().create();
schema.indexLabel("artistByName").onV("artist").by("name").ifNotExist().create();
schema.indexLabel("followedByByWeight").onE("followedBy").by("weight").range().ifNotExist().create();
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class TestGraph method initSinkSchema.
public void initSinkSchema() {
SchemaManager schema = this.graph.schema();
schema.propertyKey("name").ifNotExist().create();
schema.vertexLabel("message").properties("name").nullableKeys("name").ifNotExist().create();
schema.vertexLabel("loops").properties("name").nullableKeys("name").ifNotExist().create();
schema.edgeLabel("link").link("message", "message").ifNotExist().create();
schema.edgeLabel("self").link("loops", "loops").ifNotExist().create();
schema.indexLabel("loopsByName").onV("loops").secondary().by("name").ifNotExist().create();
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithDisableLabelIndex.
@Test
public void testAddVertexLabelWithDisableLabelIndex() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").enableLabelIndex(false).create();
Assert.assertEquals(false, person.enableLabelIndex());
graph.addVertex(T.label, "person", "name", "marko", "age", 18);
graph.addVertex(T.label, "person", "name", "josh", "age", 20);
graph().tx().commit();
List<Vertex> persons;
if (!storeFeatures().supportsQueryByLabel()) {
Assert.assertThrows(NoIndexException.class, () -> {
graph.traversal().V().hasLabel("person").toList();
});
} else {
persons = graph.traversal().V().hasLabel("person").toList();
Assert.assertEquals(2, persons.size());
}
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testRemoveVertexLabel.
@Test
public void testRemoveVertexLabel() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
Assert.assertNotNull(schema.getVertexLabel("person"));
schema.vertexLabel("person").remove();
Assert.assertThrows(NotFoundException.class, () -> {
schema.getVertexLabel("person");
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAppendVertexLabelWithNullableKeysNotInProperties.
@Test
public void testAppendVertexLabelWithNullableKeysNotInProperties() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").nullableKeys("time").append();
});
}
Aggregations