use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryVerticesByIdsWithHasIdFilterAndNumberId.
@Test
public void testQueryVerticesByIdsWithHasIdFilterAndNumberId() {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.vertexLabel("user").useCustomizeNumberId().create();
graph.addVertex(T.label, "user", T.id, 123);
graph.addVertex(T.label, "user", T.id, 456);
graph.addVertex(T.label, "user", T.id, 789);
this.mayCommitTx();
GraphTraversalSource g = graph.traversal();
List<Vertex> vertices;
vertices = g.V().hasId(P.within(123)).toList();
Assert.assertEquals(1, vertices.size());
vertices = g.V(123, 456).hasId(P.within(123)).toList();
Assert.assertEquals(1, vertices.size());
vertices = g.V(123, 456).hasId(123).toList();
Assert.assertEquals(1, vertices.size());
vertices = g.V(123, 456, 789).hasId(P.within(123, 456)).toList();
Assert.assertEquals(2, vertices.size());
vertices = g.V(123, 456, 789).hasId(456, 789).toList();
Assert.assertEquals(2, vertices.size());
vertices = g.V(123, 456, 789).hasId(P.within(123, 456, 789)).toList();
Assert.assertEquals(3, vertices.size());
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddAndUpdateVertexPropertyOfAggregateType.
@Test
public void testAddAndUpdateVertexPropertyOfAggregateType() {
Assume.assumeTrue("Not support aggregate property", storeFeatures().supportsAggregateProperty());
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.propertyKey("worstScore").asInt().valueSingle().calcMin().ifNotExist().create();
schema.propertyKey("bestScore").asInt().valueSingle().calcMax().ifNotExist().create();
schema.propertyKey("testNum").asInt().valueSingle().calcSum().ifNotExist().create();
schema.propertyKey("rank").asInt().valueSet().calcSet().ifNotExist().create();
schema.propertyKey("reword").asInt().valueList().calcList().ifNotExist().create();
schema.vertexLabel("student").properties("name", "worstScore", "bestScore", "testNum", "rank", "reword").primaryKeys("name").nullableKeys("worstScore", "bestScore", "testNum", "rank", "reword").ifNotExist().create();
Vertex tom = graph.addVertex(T.label, "student", "name", "Tom", "worstScore", 55, "bestScore", 96, "testNum", 1, "rank", 8, "reword", 8);
tom.property("worstScore", 65);
tom.property("bestScore", 94);
tom.property("testNum", 2);
tom.property("rank", 12);
tom.property("reword", 12);
Vertex result = graph.traversal().V().hasLabel("student").has("name", "Tom").next();
Assert.assertEquals(65, result.value("worstScore"));
Assert.assertEquals(94, result.value("bestScore"));
Assert.assertEquals(2, result.value("testNum"));
Assert.assertEquals(ImmutableSet.of(8, 12), result.value("rank"));
Assert.assertEquals(ImmutableList.of(8, 12), result.value("reword"));
this.commitTx();
result = graph.traversal().V().hasLabel("student").has("name", "Tom").next();
Assert.assertEquals(65, result.value("worstScore"));
Assert.assertEquals(94, result.value("bestScore"));
Assert.assertEquals(2, result.value("testNum"));
Assert.assertEquals(ImmutableSet.of(8, 12), result.value("rank"));
Assert.assertEquals(ImmutableList.of(8, 12), result.value("reword"));
tom = graph.addVertex(T.label, "student", "name", "Tom", "worstScore", 55, "bestScore", 96, "testNum", 1, "rank", 2, "reword", 2);
tom.property("worstScore", 75);
tom.property("bestScore", 92);
tom.property("testNum", 2);
tom.property("rank", 1);
tom.property("reword", 1);
Assert.assertEquals(75, tom.value("worstScore"));
Assert.assertEquals(92, tom.value("bestScore"));
Assert.assertEquals(2, tom.value("testNum"));
Assert.assertEquals(ImmutableSet.of(1, 2), tom.value("rank"));
Assert.assertEquals(ImmutableList.of(2, 1), tom.value("reword"));
Assert.assertEquals(75, tom.property("worstScore").value());
Assert.assertEquals(92, tom.property("bestScore").value());
Assert.assertEquals(2, tom.property("testNum").value());
Assert.assertEquals(ImmutableSet.of(1, 2), tom.property("rank").value());
Assert.assertEquals(ImmutableList.of(2, 1), tom.value("reword"));
this.commitTx();
result = graph.traversal().V().hasLabel("student").has("name", "Tom").next();
Assert.assertEquals(65, result.value("worstScore"));
Assert.assertEquals(94, result.value("bestScore"));
Assert.assertEquals(4, result.value("testNum"));
Assert.assertEquals(ImmutableSet.of(1, 2, 8, 12), result.value("rank"));
Assert.assertEquals(ImmutableList.of(8, 12, 2, 1), result.value("reword"));
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryByJointIndexesWithOnlyRangeIndexes.
@Test
public void testQueryByJointIndexesWithOnlyRangeIndexes() {
SchemaManager schema = graph().schema();
schema.vertexLabel("dog").properties("name", "age", "weight").create();
schema.indexLabel("dogByAge").onV("dog").range().by("age").create();
schema.indexLabel("dogByWeight").onV("dog").range().by("weight").create();
graph().addVertex(T.label, "dog", "name", "Tom", "age", 8, "weight", 3);
this.mayCommitTx();
List<Vertex> vertices = graph().traversal().V().has("age", P.gt(2)).has("weight", P.lt(10)).toList();
Assert.assertEquals(1, vertices.size());
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddVertexWithDefaultPropertyValue.
@Test
public void testAddVertexWithDefaultPropertyValue() {
SchemaManager schema = graph().schema();
schema.propertyKey("fav").asText().userdata(Userdata.DEFAULT_VALUE, "Movie").create();
schema.propertyKey("cnt").asInt().userdata(Userdata.DEFAULT_VALUE, 123).create();
schema.vertexLabel("person").properties("fav", "cnt").nullableKeys("fav", "cnt").append();
// No 'fav'
Vertex vertex = graph().addVertex(T.label, "person", "name", "Baby", "city", "Shanghai");
Assert.assertEquals("Baby", vertex.value("name"));
Assert.assertFalse(vertex.values("fav").hasNext());
Assert.assertFalse(vertex.values("age").hasNext());
vertex = graph().vertex(vertex.id());
Assert.assertEquals("Baby", vertex.value("name"));
Assert.assertFalse(vertex.values("fav").hasNext());
Assert.assertFalse(vertex.values("cnt").hasNext());
Assert.assertFalse(vertex.values("age").hasNext());
this.commitTx();
// Exist 'fav' after commit then query
vertex = graph().vertex(vertex.id());
Assert.assertEquals("Baby", vertex.value("name"));
Assert.assertEquals("Movie", vertex.value("fav"));
Assert.assertEquals(123, vertex.value("cnt"));
Assert.assertFalse(vertex.values("age").hasNext());
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryVerticesByLabelsWithOneLabelNotExist.
@Test
public void testQueryVerticesByLabelsWithOneLabelNotExist() {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.vertexLabel("user1").useCustomizeNumberId().create();
schema.vertexLabel("user2").useCustomizeNumberId().create();
graph.addVertex(T.label, "user1", T.id, 123);
graph.addVertex(T.label, "user2", T.id, 456);
graph.addVertex(T.label, "user2", T.id, 789);
this.mayCommitTx();
GraphTraversalSource g = graph.traversal();
List<Vertex> vertices;
vertices = g.V().hasLabel("user1").toList();
Assert.assertEquals(1, vertices.size());
vertices = g.V().hasLabel("user2").toList();
Assert.assertEquals(2, vertices.size());
vertices = g.V().hasLabel("user1", "user2").toList();
Assert.assertEquals(3, vertices.size());
Assert.assertThrows(IllegalArgumentException.class, () -> {
g.V().hasLabel("user3").toList();
}, e -> {
Assert.assertEquals("Undefined vertex label: 'user3'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
g.V().hasLabel("user1", "user3").toList();
}, e -> {
Assert.assertEquals("Undefined vertex label: 'user3'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
g.V().hasLabel("user3", "user1").toList();
}, e -> {
Assert.assertEquals("Undefined vertex label: 'user3'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
g.V().hasLabel("user3", "user4").toList();
}, e -> {
Assert.assertEquals("Undefined vertex label: 'user3'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
g.V().hasLabel("user4", "user3").toList();
}, e -> {
Assert.assertEquals("Undefined vertex label: 'user4'", e.getMessage());
});
}
Aggregations