Search in sources :

Example 36 with SchemaManager

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

the class VertexCoreTest method testAddVertexWithCustomizeNumberIdStrategy.

@Test
public void testAddVertexWithCustomizeNumberIdStrategy() {
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    schema.vertexLabel("programmer").useCustomizeNumberId().properties("name", "age", "city").create();
    graph.addVertex(T.label, "programmer", T.id, 123456, "name", "marko", "age", 18, "city", "Beijing");
    graph.addVertex(T.label, "programmer", T.id, 61695499031416832L, "name", "marko", "age", 19, "city", "Beijing");
    this.mayCommitTx();
    List<Vertex> vertices = graph.traversal().V(123456).toList();
    Assert.assertEquals(1, vertices.size());
    Id id = (Id) vertices.get(0).id();
    Assert.assertEquals(IdType.LONG, id.type());
    Assert.assertEquals(123456, id.asLong());
    assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
    vertices = graph.traversal().V(61695499031416832L).toList();
    Assert.assertEquals(1, vertices.size());
    id = (Id) vertices.get(0).id();
    Assert.assertEquals(IdType.LONG, id.type());
    Assert.assertEquals(61695499031416832L, id.asLong());
    assertContains(vertices, T.label, "programmer", "name", "marko", "age", 19, "city", "Beijing");
}
Also used : FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 37 with SchemaManager

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

the class VertexCoreTest method testQueryByJointIndexesWithTwoSearchAndOneRangeIndexes.

@Test
public void testQueryByJointIndexesWithTwoSearchAndOneRangeIndexes() {
    SchemaManager schema = graph().schema();
    schema.vertexLabel("dog").properties("name", "age", "description", "city").create();
    schema.indexLabel("dogByAge").onV("dog").range().by("age").create();
    schema.indexLabel("dogByDescription").onV("dog").search().by("description").create();
    schema.indexLabel("dogByCity").onV("dog").search().by("city").create();
    graph().addVertex(T.label, "dog", "name", "Bella", "age", 1, "city", "Beijing Haidian", "description", "black hair and eyes");
    graph().addVertex(T.label, "dog", "name", "Daisy", "age", 2, "city", "Shanghai Zhangjiang", "description", "yellow hair yellow tail");
    graph().addVertex(T.label, "dog", "name", "Coco", "age", 3, "city", "Shanghai Pudong", "description", "yellow hair golden tail");
    this.commitTx();
    List<Vertex> vertices;
    vertices = graph().traversal().V().has("description", Text.contains("yellow hair")).has("city", Text.contains("Shanghai")).toList();
    Assert.assertEquals(2, vertices.size());
    vertices = graph().traversal().V().has("age", P.gte(2)).has("description", Text.contains("yellow hair")).has("city", Text.contains("Zhangjiang")).toList();
    Assert.assertEquals(1, vertices.size());
    vertices = graph().traversal().V().has("age", P.gt(2)).has("description", Text.contains("yellow hair")).toList();
    Assert.assertEquals(1, vertices.size());
    vertices = graph().traversal().V().has("age", P.gt(2)).has("description", Text.contains("yellow hair")).has("city", Text.contains("Beijing")).toList();
    Assert.assertEquals(0, vertices.size());
    vertices = graph().traversal().V().has("age", P.gt(0)).has("description", Text.contains("black golden")).toList();
    Assert.assertEquals(2, vertices.size());
    vertices = graph().traversal().V().has("age", P.gt(0)).has("description", Text.contains("black golden")).has("city", Text.contains("Beijing")).toList();
    Assert.assertEquals(1, vertices.size());
    vertices = graph().traversal().V().has("age", P.gt(0)).has("description", Text.contains("black golden")).has("city", Text.contains("Chaoyang")).toList();
    Assert.assertEquals(0, 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)

Example 38 with SchemaManager

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

the class VertexCoreTest method testAddVerticesWithUniqueIndexInTx.

@Test
public void testAddVerticesWithUniqueIndexInTx() {
    SchemaManager schema = graph().schema();
    schema.vertexLabel("user").properties("name").create();
    schema.indexLabel("userByName").onV("user").by("name").unique().create();
    graph().addVertex(T.label, "user", "name", "Tom");
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph().addVertex(T.label, "user", "name", "Tom");
        this.commitTx();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 39 with SchemaManager

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

the class VertexCoreTest method testAddVertexWithAppendedNullableKeysAbsent.

@Test
public void testAddVertexWithAppendedNullableKeysAbsent() {
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").nullableKeys("city").append();
    // Absent 'age' and 'city'
    Vertex vertex = graph().addVertex(T.label, "person", "name", "Baby");
    Assert.assertEquals("Baby", vertex.value("name"));
    this.mayCommitTx();
}
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 40 with SchemaManager

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

the class VertexCoreTest method testAddVertexWithInvalidPropertyValueOfInt.

@Test
public void testAddVertexWithInvalidPropertyValueOfInt() {
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    schema.propertyKey("int").asInt().create();
    schema.vertexLabel("number").properties("int").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        long value = Integer.MAX_VALUE + 1L;
        graph.addVertex(T.label, "number", "int", value);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        long value = Integer.MIN_VALUE - 1L;
        graph.addVertex(T.label, "number", "int", value);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.addVertex(T.label, "number", "int", Long.MAX_VALUE);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.addVertex(T.label, "number", "int", Long.MIN_VALUE);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) 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