Search in sources :

Example 91 with SchemaManager

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

the class EdgeLabelCoreTest method testAppendEdgeLabelWithUserdata.

@Test
public void testAppendEdgeLabelWithUserdata() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
    schema.vertexLabel("book").properties("name").primaryKeys("name").create();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("time", "weight").userdata("multiplicity", "one-to-many").create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    write = schema.edgeLabel("write").userdata("icon", "picture2").append();
    Assert.assertEquals(3, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    Assert.assertEquals("picture2", write.userdata().get("icon"));
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 92 with SchemaManager

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithIllegalName.

@Test
public void testAddEdgeLabelWithIllegalName() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
    // Empty string
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("").link("person", "author").create();
    });
    // One space
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel(" ").link("person", "author").create();
    });
    // Two spaces
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("  ").link("person", "author").create();
    });
    // Multi spaces
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("    ").link("person", "author").create();
    });
    // Start with '~'
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("~").link("person", "author").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("~ ").link("person", "author").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("~x").link("person", "author").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 93 with SchemaManager

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithoutProperty.

@Test
public void testAddEdgeLabelWithoutProperty() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    EdgeLabel look = schema.edgeLabel("look").singleTime().link("person", "book").create();
    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(0, look.properties().size());
    Assert.assertEquals(0, look.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, look.frequency());
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 94 with SchemaManager

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithNullableKeysIntersectSortkeys.

@Test
public void testAddEdgeLabelWithNullableKeysIntersectSortkeys() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("look").multiTimes().properties("time", "weight").sortKeys("time").nullableKeys("time").link("person", "book").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("look").multiTimes().properties("time", "weight").sortKeys("time", "weight").nullableKeys("time").link("person", "book").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("look").multiTimes().properties("time", "weight").sortKeys("time").nullableKeys("time", "weight").link("person", "book").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 95 with SchemaManager

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

the class EdgeLabelCoreTest method testAppendEdgeLabelNewEdgeWithNullableKeysAbsent.

@Test
public void testAppendEdgeLabelNewEdgeWithNullableKeysAbsent() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    schema.edgeLabel("look").properties("time", "weight").nullableKeys("weight").link("person", "book").create();
    Vertex baby = graph().addVertex(T.label, "person", "name", "Baby", "age", 3, "city", "Beijing");
    Vertex java = graph().addVertex(T.label, "book", "id", 123456, "name", "Java in action");
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        // Absent 'time'
        baby.addEdge("look", java, "weight", 0.5);
    });
    schema.edgeLabel("look").nullableKeys("time").append();
    // Absent 'time'
    Edge edge = baby.addEdge("look", java, "weight", 0.5);
    Assert.assertEquals("look", edge.label());
    Assert.assertEquals(0.5, edge.property("weight").value());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Edge(org.apache.tinkerpop.gremlin.structure.Edge) 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