Search in sources :

Example 66 with SchemaManager

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

the class VertexLabelCoreTest method testAddVertexLabelWithoutPKStrategyButCallPrimaryKey.

@Test
public void testAddVertexLabelWithoutPKStrategyButCallPrimaryKey() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").useAutomaticId().primaryKeys("name").properties("name", "age", "city").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").useCustomizeStringId().primaryKeys("name").properties("name", "age", "city").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").useCustomizeNumberId().primaryKeys("name").properties("name", "age", "city").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 67 with SchemaManager

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

the class VertexLabelCoreTest method testAppendVertexLabelWithNonNullProperties.

@Test
public void testAppendVertexLabelWithNonNullProperties() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age").primaryKeys("name").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").properties("city").append();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 68 with SchemaManager

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

the class VertexLabelCoreTest method testAddVertexWithDefaultIdStrategyAndPassedPk.

@Test
public void testAddVertexWithDefaultIdStrategyAndPassedPk() {
    super.initPropertyKeys();
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age").primaryKeys("name").create();
    Assert.assertEquals(IdStrategy.PRIMARY_KEY, person.idStrategy());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 69 with SchemaManager

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

the class MultiGraphsTest method testCopySchemaWithMultiGraphs.

@Test
public void testCopySchemaWithMultiGraphs() {
    List<HugeGraph> graphs = openGraphs("schema_g1", "schema_g2");
    for (HugeGraph graph : graphs) {
        graph.initBackend();
    }
    HugeGraph g1 = graphs.get(0);
    g1.serverStarted(IdGenerator.of("server-g2"), NodeRole.MASTER);
    HugeGraph g2 = graphs.get(1);
    g2.serverStarted(IdGenerator.of("server-g3"), NodeRole.MASTER);
    SchemaManager schema = g1.schema();
    schema.propertyKey("id").asInt().create();
    schema.propertyKey("name").asText().create();
    schema.propertyKey("age").asInt().valueSingle().create();
    schema.propertyKey("city").asText().create();
    schema.propertyKey("weight").asDouble().valueList().create();
    schema.propertyKey("born").asDate().ifNotExist().create();
    schema.propertyKey("time").asDate().ifNotExist().create();
    schema.vertexLabel("person").properties("id", "name", "age", "city", "weight", "born").primaryKeys("id").create();
    schema.vertexLabel("person2").properties("id", "name", "age", "city").primaryKeys("id").create();
    schema.edgeLabel("friend").sourceLabel("person").targetLabel("person").properties("time").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("friendByTime").onE("friend").range().by("time").create();
    Assert.assertFalse(g2.existsPropertyKey("id"));
    Assert.assertFalse(g2.existsPropertyKey("name"));
    Assert.assertFalse(g2.existsPropertyKey("age"));
    Assert.assertFalse(g2.existsPropertyKey("city"));
    Assert.assertFalse(g2.existsPropertyKey("weight"));
    Assert.assertFalse(g2.existsPropertyKey("born"));
    Assert.assertFalse(g2.existsPropertyKey("time"));
    Assert.assertFalse(g2.existsVertexLabel("person"));
    Assert.assertFalse(g2.existsVertexLabel("person2"));
    Assert.assertFalse(g2.existsEdgeLabel("friend"));
    Assert.assertFalse(g2.existsIndexLabel("personByName"));
    Assert.assertFalse(g2.existsIndexLabel("personByCity"));
    Assert.assertFalse(g2.existsIndexLabel("personByAge"));
    Assert.assertFalse(g2.existsIndexLabel("friendByTime"));
    // Copy schema from g1 to g2
    g2.schema().copyFrom(g1.schema());
    Assert.assertTrue(g2.existsPropertyKey("id"));
    Assert.assertTrue(g2.existsPropertyKey("name"));
    Assert.assertTrue(g2.existsPropertyKey("age"));
    Assert.assertTrue(g2.existsPropertyKey("city"));
    Assert.assertTrue(g2.existsPropertyKey("weight"));
    Assert.assertTrue(g2.existsPropertyKey("born"));
    Assert.assertTrue(g2.existsPropertyKey("time"));
    Assert.assertTrue(g2.existsVertexLabel("person"));
    Assert.assertTrue(g2.existsVertexLabel("person2"));
    Assert.assertTrue(g2.existsEdgeLabel("friend"));
    Assert.assertTrue(g2.existsIndexLabel("personByName"));
    Assert.assertTrue(g2.existsIndexLabel("personByCity"));
    Assert.assertTrue(g2.existsIndexLabel("personByAge"));
    Assert.assertTrue(g2.existsIndexLabel("friendByTime"));
    for (PropertyKey copied : g2.schema().getPropertyKeys()) {
        PropertyKey origin = g1.schema().getPropertyKey(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (VertexLabel copied : schema.getVertexLabels()) {
        VertexLabel origin = g1.schema().getVertexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (EdgeLabel copied : schema.getEdgeLabels()) {
        EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (IndexLabel copied : schema.getIndexLabels()) {
        IndexLabel origin = g1.schema().getIndexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    // Copy schema again from g1 to g2 (ignore identical content)
    g2.schema().copyFrom(g1.schema());
    for (PropertyKey copied : g2.schema().getPropertyKeys()) {
        PropertyKey origin = g1.schema().getPropertyKey(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (VertexLabel copied : schema.getVertexLabels()) {
        VertexLabel origin = g1.schema().getVertexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (EdgeLabel copied : schema.getEdgeLabels()) {
        EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (IndexLabel copied : schema.getIndexLabels()) {
        IndexLabel origin = g1.schema().getIndexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (HugeGraph graph : graphs) {
        graph.clearBackend();
    }
    destroyGraphs(graphs);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Example 70 with SchemaManager

use of com.baidu.hugegraph.schema.SchemaManager 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)

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