Search in sources :

Example 51 with SchemaManager

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();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 52 with SchemaManager

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();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager)

Example 53 with SchemaManager

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());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 54 with SchemaManager

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");
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 55 with SchemaManager

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();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Aggregations

SchemaManager (com.baidu.hugegraph.schema.SchemaManager)261 Test (org.junit.Test)227 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)90 HugeGraph (com.baidu.hugegraph.HugeGraph)76 FakeVertex (com.baidu.hugegraph.testutil.FakeObjects.FakeVertex)40 Edge (org.apache.tinkerpop.gremlin.structure.Edge)30 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)27 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)22 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)20 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)19 FakeEdge (com.baidu.hugegraph.testutil.FakeObjects.FakeEdge)19 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)15 Id (com.baidu.hugegraph.backend.id.Id)12 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)7 Date (java.util.Date)6 Before (org.junit.Before)6 HashSet (java.util.HashSet)3 HugeException (com.baidu.hugegraph.HugeException)2