use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryByIdNotFound.
@Test
public void testQueryByIdNotFound() {
HugeGraph graph = graph();
init10Vertices();
// Query vertex by id which not exists
Id id = SplicingIdGenerator.splicing("author", "not-exists-id");
Assert.assertTrue(graph.traversal().V(id).toList().isEmpty());
Assert.assertThrows(NoSuchElementException.class, () -> {
graph.traversal().V(id).next();
});
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddVertexWithCustomizeUuidIdStrategy.
@Test
public void testAddVertexWithCustomizeUuidIdStrategy() {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.vertexLabel("programmer").useCustomizeUuidId().properties("name", "age", "city").create();
graph.addVertex(T.label, "programmer", T.id, "835e1153-9281-4957-8691-cf79258e90eb", "name", "marko", "age", 18, "city", "Beijing");
graph.addVertex(T.label, "programmer", T.id, UUID.fromString("835e1153-9281-4957-8691-cf79258e90eb"), "name", "marko", "age", 18, "city", "Beijing");
graph.addVertex(T.label, "programmer", T.id, "835e1153928149578691cf79258e90ee", "name", "marko", "age", 19, "city", "Beijing");
this.commitTx();
Assert.assertEquals(2L, graph.traversal().V().count().next());
Object uuid = Text.uuid("835e1153928149578691cf79258e90eb");
List<Vertex> vertices = graph.traversal().V(uuid).toList();
Assert.assertEquals(1, vertices.size());
Id id = (Id) vertices.get(0).id();
Assert.assertEquals(IdType.UUID, id.type());
Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb", id.asString());
assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
uuid = Text.uuid("835e1153-9281-4957-8691-cf79258e90ee");
vertices = graph.traversal().V(uuid).toList();
Assert.assertEquals(1, vertices.size());
id = (Id) vertices.get(0).id();
Assert.assertEquals(IdType.UUID, id.type());
Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90ee", id.asString());
assertContains(vertices, T.label, "programmer", "name", "marko", "age", 19, "city", "Beijing");
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddOlapRangeAndOlapSecondaryProperties.
@Test
public void testAddOlapRangeAndOlapSecondaryProperties() {
Assume.assumeTrue("Not support olap properties", storeFeatures().supportsOlapProperties());
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
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));
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(), "pagerank", 0.1D);
graph.addVertex(T.id, id2.asObject(), "pagerank", 0.2D);
graph.addVertex(T.id, id3.asObject(), "pagerank", 0.3D);
graph.addVertex(T.id, id4.asObject(), "pagerank", 0.4D);
graph.addVertex(T.id, id5.asObject(), "pagerank", 0.5D);
graph.addVertex(T.id, id6.asObject(), "pagerank", 0.6D);
graph.addVertex(T.id, id7.asObject(), "pagerank", 0.7D);
graph.addVertex(T.id, id8.asObject(), "pagerank", 0.8D);
graph.addVertex(T.id, id9.asObject(), "pagerank", 0.9D);
graph.addVertex(T.id, id10.asObject(), "pagerank", 1.0D);
this.commitTx();
graph.addVertex(T.id, id1.asObject(), "wcc", "a");
graph.addVertex(T.id, id2.asObject(), "wcc", "a");
graph.addVertex(T.id, id3.asObject(), "wcc", "c");
graph.addVertex(T.id, id4.asObject(), "wcc", "c");
graph.addVertex(T.id, id5.asObject(), "wcc", "c");
graph.addVertex(T.id, id6.asObject(), "wcc", "f");
graph.addVertex(T.id, id7.asObject(), "wcc", "f");
graph.addVertex(T.id, id8.asObject(), "wcc", "f");
graph.addVertex(T.id, id9.asObject(), "wcc", "f");
graph.addVertex(T.id, id10.asObject(), "wcc", "f");
this.commitTx();
Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode());
Assert.assertThrows(NotAllowException.class, () -> {
graph.traversal().V().has("pagerank", 0.1D).has("wcc", "a").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.3D).has("wcc", "b").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.6D).has("wcc", "f").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("wcc", "a").toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V().has("pagerank", 0.3D).has("wcc", "c").toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id3).next(), vertices.get(0));
vertices = graph.traversal().V().has("pagerank", 0.6D).has("wcc", "f").toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id6).next(), vertices.get(0));
vertices = graph.traversal().V().has("pagerank", P.gt(0.9D)).has("wcc", "f").toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id10).next(), vertices.get(0));
vertices = graph.traversal().V().has("pagerank", P.lt(0.2D)).has("wcc", "a").toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(graph.traversal().V(id1).next(), vertices.get(0));
vertices = graph.traversal().V().has("pagerank", P.gte(0.9D)).has("wcc", "f").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("pagerank", P.lte(0.2D)).has("wcc", "a").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("pagerank", P.inside(0.2D, 0.9D)).has("wcc", "c").toList();
Assert.assertEquals(3, 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()));
vertices = graph.traversal().V().has("pagerank", P.inside(0.2D, 0.9D)).has("wcc", "f").toList();
Assert.assertEquals(3, vertices.size());
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);
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddOlapRangeProperties.
@Test
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);
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddVertexWithCustomizeStringIdStrategy.
@Test
public void testAddVertexWithCustomizeStringIdStrategy() {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.vertexLabel("programmer").useCustomizeStringId().properties("name", "age", "city").create();
graph.addVertex(T.label, "programmer", T.id, "123456", "name", "marko", "age", 18, "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.STRING, id.type());
Assert.assertEquals("123456", id.asString());
assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
}
Aggregations