in hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java [2262:2381]
public void testAddOlapRangeProperties() {
Assume.assumeTrue("Not support olap properties",
storeFeatures().supportsOlapProperties());
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
String olapPropName = "pagerank";
schema.propertyKey(olapPropName)
.asDouble().valueSingle()
.writeType(WriteType.OLAP_RANGE)
.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));
String language = graph.vertexLabel("language").id().asString();
Id id3 = SplicingIdGenerator.splicing(language, "java");
Id id4 = SplicingIdGenerator.splicing(language, "c++");
Id id5 = SplicingIdGenerator.splicing(language, "python");
String book = graph.vertexLabel("book").id().asString();
Id id6 = SplicingIdGenerator.splicing(book, "java-1");
Id id7 = SplicingIdGenerator.splicing(book, "java-2");
Id id8 = SplicingIdGenerator.splicing(book, "java-3");
Id id9 = SplicingIdGenerator.splicing(book, "java-4");
Id id10 = SplicingIdGenerator.splicing(book, "java-5");
graph.addVertex(T.id, id1.asObject(), olapPropName, 0.1D);
graph.addVertex(T.id, id2.asObject(), olapPropName, 0.2D);
graph.addVertex(T.id, id3.asObject(), olapPropName, 0.3D);
graph.addVertex(T.id, id4.asObject(), olapPropName, 0.4D);
graph.addVertex(T.id, id5.asObject(), olapPropName, 0.5D);
graph.addVertex(T.id, id6.asObject(), olapPropName, 0.6D);
graph.addVertex(T.id, id7.asObject(), olapPropName, 0.7D);
graph.addVertex(T.id, id8.asObject(), olapPropName, 0.8D);
graph.addVertex(T.id, id9.asObject(), olapPropName, 0.9D);
graph.addVertex(T.id, id10.asObject(), olapPropName, 1.0D);
this.commitTx();
Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode());
Assert.assertThrows(NotAllowException.class, () -> {
graph.traversal().V().has(olapPropName, 0.1D).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(olapPropName, 0.3D).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(olapPropName, 0.6D).hasNext();
}, e -> {
Assert.assertContains("Not allowed to query by olap property key",
e.getMessage());
});
graph.traversal().V(id1).next();
graph.readMode(GraphReadMode.ALL);
List<Vertex> vertices = graph.traversal().V()
.has(olapPropName, 0.1D).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V().has(olapPropName, 0.3D).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id3).next(), vertices.get(0));
vertices = graph.traversal().V().has(olapPropName, 0.6D).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id6).next(), vertices.get(0));
vertices = graph.traversal().V().has(olapPropName, P.gt(0.9D)).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id10).next(),
vertices.get(0));
vertices = graph.traversal().V().has(olapPropName, P.lt(0.2D)).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V().has(olapPropName, P.gte(0.9D))
.toList();
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertices.contains(graph.traversal().V(id9).next()));
Assert.assertTrue(vertices.contains(
graph.traversal().V(id10).next()));
vertices = graph.traversal().V().has(olapPropName, P.lte(0.2D))
.toList();
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertices.contains(graph.traversal().V(id1).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id2).next()));
vertices = graph.traversal().V()
.has(olapPropName, P.inside(0.2D, 0.9D)).toList();
Assert.assertEquals(6, vertices.size());
Assert.assertTrue(vertices.contains(graph.traversal().V(id3).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id4).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id5).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id6).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id7).next()));
Assert.assertTrue(vertices.contains(graph.traversal().V(id8).next()));
graph.readMode(GraphReadMode.OLTP_ONLY);
}