use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class NeighborRankApiTest method initNeighborRankGraph.
@BeforeClass
public static void initNeighborRankGraph() {
GraphManager graph = graph();
SchemaManager schema = schema();
schema.propertyKey("name").asText().ifNotExist().create();
schema.vertexLabel("person").properties("name").useCustomizeStringId().ifNotExist().create();
schema.vertexLabel("movie").properties("name").useCustomizeStringId().ifNotExist().create();
schema.edgeLabel("follow").sourceLabel("person").targetLabel("person").ifNotExist().create();
schema.edgeLabel("like").sourceLabel("person").targetLabel("movie").ifNotExist().create();
schema.edgeLabel("directedBy").sourceLabel("movie").targetLabel("person").ifNotExist().create();
Vertex O = graph.addVertex(T.label, "person", T.id, "O", "name", "O");
Vertex A = graph.addVertex(T.label, "person", T.id, "A", "name", "A");
Vertex B = graph.addVertex(T.label, "person", T.id, "B", "name", "B");
Vertex C = graph.addVertex(T.label, "person", T.id, "C", "name", "C");
Vertex D = graph.addVertex(T.label, "person", T.id, "D", "name", "D");
Vertex E = graph.addVertex(T.label, "movie", T.id, "E", "name", "E");
Vertex F = graph.addVertex(T.label, "movie", T.id, "F", "name", "F");
Vertex G = graph.addVertex(T.label, "movie", T.id, "G", "name", "G");
Vertex H = graph.addVertex(T.label, "movie", T.id, "H", "name", "H");
Vertex I = graph.addVertex(T.label, "movie", T.id, "I", "name", "I");
Vertex J = graph.addVertex(T.label, "movie", T.id, "J", "name", "J");
Vertex K = graph.addVertex(T.label, "person", T.id, "K", "name", "K");
Vertex L = graph.addVertex(T.label, "person", T.id, "L", "name", "L");
Vertex M = graph.addVertex(T.label, "person", T.id, "M", "name", "M");
O.addEdge("follow", A);
O.addEdge("follow", B);
O.addEdge("follow", C);
D.addEdge("follow", O);
A.addEdge("follow", B);
A.addEdge("like", E);
A.addEdge("like", F);
B.addEdge("like", G);
B.addEdge("like", H);
C.addEdge("like", I);
C.addEdge("like", J);
E.addEdge("directedBy", K);
F.addEdge("directedBy", B);
F.addEdge("directedBy", L);
G.addEdge("directedBy", M);
}
use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class CustomizedPathsApiTest method initEdgesWithWeights.
private static void initEdgesWithWeights() {
SchemaManager schema = schema();
schema.edgeLabel("knows1").sourceLabel("person").targetLabel("person").properties("date", "weight").nullableKeys("weight").ifNotExist().create();
schema.edgeLabel("created1").sourceLabel("person").targetLabel("software").properties("date", "weight").nullableKeys("weight").ifNotExist().create();
Vertex marko = getVertex("person", "name", "marko");
Vertex vadas = getVertex("person", "name", "vadas");
Vertex lop = getVertex("software", "name", "lop");
Vertex josh = getVertex("person", "name", "josh");
Vertex ripple = getVertex("software", "name", "ripple");
Vertex peter = getVertex("person", "name", "peter");
marko.addEdge("knows1", vadas, "date", "2016-01-10", "weight", 0.5);
marko.addEdge("knows1", josh, "date", "2013-02-20", "weight", 1.0);
marko.addEdge("created1", lop, "date", "2017-12-10", "weight", 0.4);
josh.addEdge("created1", lop, "date", "2009-11-11", "weight", 0.4);
josh.addEdge("created1", ripple, "date", "2017-12-10", "weight", 1.0);
peter.addEdge("created1", lop, "date", "2017-03-24", "weight", 0.2);
}
use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class VertexApiTest method testCreateVertexWithTtl.
@Test
public void testCreateVertexWithTtl() {
SchemaManager schema = schema();
schema.vertexLabel("fan").properties("name", "age", "city").primaryKeys("name").ttl(3000L).ifNotExist().create();
Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing");
Vertex result = graph().getVertex(vertex.id());
Assert.assertEquals("fan", result.label());
Map<String, Object> props = ImmutableMap.of("name", "Baby", "city", "Beijing", "age", 3);
Assert.assertEquals(props, result.properties());
try {
Thread.sleep(1100L);
} catch (InterruptedException e) {
// Ignore
}
result = graph().getVertex(vertex.id());
Assert.assertEquals("fan", result.label());
Assert.assertEquals(props, result.properties());
try {
Thread.sleep(1100L);
} catch (InterruptedException e) {
// Ignore
}
result = graph().getVertex(vertex.id());
Assert.assertEquals("fan", result.label());
Assert.assertEquals(props, result.properties());
try {
Thread.sleep(1100L);
} catch (InterruptedException e) {
// Ignore
}
Assert.assertThrows(ServerException.class, () -> {
graph().getVertex(vertex.id());
}, e -> {
Assert.assertContains("does not exist", e.getMessage());
});
}
use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class SchemaService method collectIndexLabels.
public static List<IndexLabel> collectIndexLabels(SchemaLabelEntity entity, HugeClient client) {
List<PropertyIndex> propertyIndexes = entity.getPropertyIndexes();
if (CollectionUtils.isEmpty(propertyIndexes)) {
return Collections.emptyList();
}
boolean isVertex = entity.getSchemaType().isVertexLabel();
String baseValue = entity.getName();
SchemaManager schema = client.schema();
List<IndexLabel> indexLabels = new ArrayList<>(propertyIndexes.size());
for (PropertyIndex index : propertyIndexes) {
String[] fields = toStringArray(index.getFields());
IndexLabel indexLabel = schema.indexLabel(index.getName()).on(isVertex, baseValue).indexType(index.getType()).by(fields).build();
indexLabels.add(indexLabel);
}
return indexLabels;
}
use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelTest method testRemoveEdgeLabelAsync.
@Test
public void testRemoveEdgeLabelAsync() {
SchemaManager schema = schema();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
Assert.assertNotNull(write);
// Remove edge label async and wait
long taskId = schema.removeEdgeLabelAsync("write");
Task task = task().waitUntilTaskCompleted(taskId, 10);
Assert.assertTrue(task.completed());
}
Aggregations