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");
}
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());
}
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();
});
}
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();
}
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);
});
}
Aggregations