Search in sources :

Example 16 with SchemaManager

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

the class VertexCoreTest method testUpdatePropertyToValueOfRemovedVertexWithUniqueIndex.

@Test
public void testUpdatePropertyToValueOfRemovedVertexWithUniqueIndex() {
    SchemaManager schema = graph().schema();
    schema.vertexLabel("user").properties("name").create();
    schema.indexLabel("userByName").onV("user").by("name").unique().create();
    Vertex tom = graph().addVertex(T.label, "user", "name", "Tom");
    Vertex jack = graph().addVertex(T.label, "user", "name", "Jack");
    Vertex james = graph().addVertex(T.label, "user", "name", "James");
    this.commitTx();
    tom.remove();
    this.commitTx();
    jack.property("name", "Tom");
    this.commitTx();
    james.remove();
    jack.property("name", "James");
    this.commitTx();
}
Also used : FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 17 with SchemaManager

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

the class VertexCoreTest method initComputerIndex.

protected void initComputerIndex() {
    SchemaManager schema = graph().schema();
    LOG.debug("===============  computer index  ================");
    schema.indexLabel("pcByBand").onV("computer").secondary().by("band").ifNotExist().create();
    schema.indexLabel("pcByCpuAndRamAndBand").onV("computer").secondary().by("cpu", "ram", "band").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager)

Example 18 with SchemaManager

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

the class VertexCoreTest method testAddVertexWithAutomaticIdStrategyButPassedId.

@Test
public void testAddVertexWithAutomaticIdStrategyButPassedId() {
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    schema.vertexLabel("programmer").useAutomaticId().properties("name", "age", "city").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.addVertex(T.label, "programmer", T.id, "123456", "name", "marko", "age", 18, "city", "Beijing");
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 19 with SchemaManager

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

the class VertexCoreTest method testAddVertexWithCustomizeStringIdStrategyWithoutValidId.

@Test
public void testAddVertexWithCustomizeStringIdStrategyWithoutValidId() {
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    schema.vertexLabel("programmer").useCustomizeStringId().properties("name", "age", "city").create();
    // Expect id, but no id
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
    });
    // Expect string id, but got number id
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.addVertex(T.label, "programmer", T.id, 123456, "name", "marko", "age", 18, "city", "Beijing");
    });
    // Expect id length <= 128
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        String largeId = new String(new byte[128]) + ".";
        assert largeId.length() == 129;
        graph.addVertex(T.label, "programmer", T.id, largeId, "name", "marko", "age", 18, "city", "Beijing");
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 20 with SchemaManager

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

the class VertexCoreTest method testQueryByJointIndexesOnlyWithCompositeIndex.

@Test
public void testQueryByJointIndexesOnlyWithCompositeIndex() {
    SchemaManager schema = graph().schema();
    schema.vertexLabel("dog").properties("name", "age", "city").nullableKeys("age").create();
    schema.indexLabel("dogByNameAndCity").onV("dog").secondary().by("name", "city").create();
    schema.indexLabel("dogByCityAndAge").onV("dog").secondary().by("city", "age").create();
    graph().addVertex(T.label, "dog", "name", "Tom", "city", "Hongkong", "age", 3);
    this.mayCommitTx();
    List<Vertex> vertices = graph().traversal().V().has("age", 3).has("city", "Hongkong").has("name", "Tom").toList();
    Assert.assertEquals(1, vertices.size());
}
Also used : FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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