Search in sources :

Example 1 with SchemaManager

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);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) BeforeClass(org.junit.BeforeClass)

Example 2 with SchemaManager

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);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager)

Example 3 with SchemaManager

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());
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 4 with SchemaManager

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;
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 5 with SchemaManager

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());
}
Also used : Task(com.baidu.hugegraph.structure.Task) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Aggregations

SchemaManager (com.baidu.hugegraph.driver.SchemaManager)61 Test (org.junit.Test)39 Vertex (com.baidu.hugegraph.structure.graph.Vertex)18 Date (java.util.Date)14 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)11 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 BeforeClass (org.junit.BeforeClass)8 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)6 Edge (com.baidu.hugegraph.structure.graph.Edge)4 ArrayList (java.util.ArrayList)3 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)2 Task (com.baidu.hugegraph.structure.Task)2 Result (com.baidu.hugegraph.structure.gremlin.Result)2 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)2 BaseClientTest (com.baidu.hugegraph.BaseClientTest)1 GremlinManager (com.baidu.hugegraph.driver.GremlinManager)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1