in hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java [2554:2676]
public void testQueryOlapRangeAndRegularSecondaryProperties() {
Assume.assumeTrue("Not support olap properties",
storeFeatures().supportsOlapProperties());
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.indexLabel("authorByAge").onV("author").range()
.by("age").create();
schema.indexLabel("authorByLived").onV("author").secondary()
.by("lived").create();
schema.propertyKey("pagerank")
.asDouble().valueSingle()
.writeType(WriteType.OLAP_RANGE)
.ifNotExist().create();
schema.propertyKey("wcc")
.asText().valueSingle()
.writeType(WriteType.OLAP_SECONDARY)
.ifNotExist().create();
this.init10VerticesAndCommit();
String author = graph.vertexLabel("author").id().asString();
Id id1 = SplicingIdGenerator.splicing(author,
LongEncoding.encodeNumber(1));
Id id2 = SplicingIdGenerator.splicing(author,
LongEncoding.encodeNumber(2));
graph.addVertex(T.id, id1.asObject(), "pagerank", 0.1D);
graph.addVertex(T.id, id2.asObject(), "pagerank", 0.2D);
this.commitTx();
graph.addVertex(T.id, id1.asObject(), "wcc", "a");
graph.addVertex(T.id, id2.asObject(), "wcc", "b");
this.commitTx();
Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode());
Assert.assertThrows(NotAllowException.class, () -> {
graph.traversal().V()
.has("pagerank", 0.1D)
.has("lived", "Canadian")
.hasNext();
}, e -> {
Assert.assertContains("Not allowed to query by olap property key",
e.getMessage());
});
Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode());
Assert.assertThrows(NotAllowException.class, () -> {
graph.traversal().V()
.has("wcc", "a")
.has("age", 62)
.hasNext();
}, e -> {
Assert.assertContains("Not allowed to query by olap property key",
e.getMessage());
});
Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode());
Assert.assertThrows(NotAllowException.class, () -> {
graph.traversal().V()
.has("pagerank", 0.1D)
.has("age", 62)
.hasNext();
}, e -> {
Assert.assertContains("Not allowed to query by olap property key",
e.getMessage());
});
graph.readMode(GraphReadMode.ALL);
List<Vertex> vertices = graph.traversal().V()
.has("pagerank", 0.1D)
.has("lived", "Canadian")
.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V()
.has("pagerank", P.lte(0.1D))
.has("age", P.gte(62))
.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V()
.has("pagerank", P.lte(0.1D))
.has("age", P.gte(62))
.has("lived", "Canadian")
.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V()
.has("age", P.gt(5))
.has("wcc", "b")
.toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id2).next(), vertices.get(0));
vertices = graph.traversal().V()
.has("pagerank", P.gte(0.1D))
.has("age", P.gte(10))
.toList();
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertices.contains(graph.traversal().V(id1).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id2).next()));
Set<Vertex> vertexSet = graph.traversal().V()
.has("pagerank", P.lte(0.9D))
.has("wcc", P.within("a", "b"))
.has("age", P.gt(20))
.has("lived", P.within("Canadian",
"California"))
.toSet();
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertexSet.contains(graph.traversal().V(id1).next()));
Assert.assertTrue(vertexSet.contains(graph.traversal().V(id2).next()));
graph.readMode(GraphReadMode.OLTP_ONLY);
}