Search in sources :

Example 21 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class VertexLabelTest method testAppendVertexLabelWithUserData.

@Test
public void testAppendVertexLabelWithUserData() {
    SchemaManager schema = schema();
    VertexLabel player = schema.vertexLabel("player").properties("name").create();
    Assert.assertEquals(1, player.userdata().size());
    String time = (String) player.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    try {
        Thread.sleep(10);
    } catch (InterruptedException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertTrue(createTime.before(DateUtil.now()));
    player = schema.vertexLabel("player").userdata("super_vl", "person").append();
    Assert.assertEquals(2, player.userdata().size());
    Assert.assertEquals("person", player.userdata().get("super_vl"));
    time = (String) player.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 22 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class VertexLabelTest method testSetCheckExist.

@Test
public void testSetCheckExist() {
    SchemaManager schema = schema();
    VertexLabel player = schema.vertexLabel("player").properties("name").build();
    Assert.assertTrue(player.checkExist());
    player.checkExist(false);
    Assert.assertFalse(player.checkExist());
}
Also used : VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 23 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class GraphsApiTest method initVertexLabel.

protected static void initVertexLabel(HugeClient client) {
    SchemaManager schema = client.schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").ifNotExist().create();
    schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").nullableKeys("price").ifNotExist().create();
    schema.vertexLabel("book").useCustomizeStringId().properties("name", "price").nullableKeys("price").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager)

Example 24 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class SingleExample method main.

public static void main(String[] args) throws IOException {
    // If connect failed will throw a exception.
    HugeClient hugeClient = HugeClient.builder("http://localhost:8080", "hugegraph").build();
    SchemaManager schema = hugeClient.schema();
    schema.propertyKey("name").asText().ifNotExist().create();
    schema.propertyKey("age").asInt().ifNotExist().create();
    schema.propertyKey("city").asText().ifNotExist().create();
    schema.propertyKey("weight").asDouble().ifNotExist().create();
    schema.propertyKey("lang").asText().ifNotExist().create();
    schema.propertyKey("date").asDate().ifNotExist().create();
    schema.propertyKey("price").asInt().ifNotExist().create();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create();
    schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create();
    schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create();
    schema.indexLabel("personByAgeAndCity").onV("person").by("age", "city").secondary().ifNotExist().create();
    schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create();
    schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date", "weight").ifNotExist().create();
    schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "weight").ifNotExist().create();
    schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create();
    schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create();
    schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create();
    GraphManager graph = hugeClient.graph();
    Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing");
    Vertex vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong");
    Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328);
    Vertex josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city", "Beijing");
    Vertex ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang", "java", "price", 199);
    Vertex peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city", "Shanghai");
    marko.addEdge("knows", vadas, "date", "2016-01-10", "weight", 0.5);
    marko.addEdge("knows", josh, "date", "2013-02-20", "weight", 1.0);
    marko.addEdge("created", lop, "date", "2017-12-10", "weight", 0.4);
    josh.addEdge("created", lop, "date", "2009-11-11", "weight", 0.4);
    josh.addEdge("created", ripple, "date", "2017-12-10", "weight", 1.0);
    peter.addEdge("created", lop, "date", "2017-03-24", "weight", 0.2);
    GremlinManager gremlin = hugeClient.gremlin();
    System.out.println("==== Path ====");
    ResultSet resultSet = gremlin.gremlin("g.V().outE().path()").execute();
    Iterator<Result> results = resultSet.iterator();
    results.forEachRemaining(result -> {
        System.out.println(result.getObject().getClass());
        Object object = result.getObject();
        if (object instanceof Vertex) {
            System.out.println(((Vertex) object).id());
        } else if (object instanceof Edge) {
            System.out.println(((Edge) object).id());
        } else if (object instanceof Path) {
            List<Object> elements = ((Path) object).objects();
            elements.forEach(element -> {
                System.out.println(element.getClass());
                System.out.println(element);
            });
        } else {
            System.out.println(object);
        }
    });
    hugeClient.close();
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) GremlinManager(com.baidu.hugegraph.driver.GremlinManager) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result)

Example 25 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project hugegraph-computer by hugegraph.

the class TriangleCountTest method setup.

@BeforeClass
public static void setup() {
    clearAll();
    SchemaManager schema = client().schema();
    schema.propertyKey(PROPERTY_KEY).asInt().ifNotExist().create();
    schema.vertexLabel(VERTX_LABEL).properties(PROPERTY_KEY).useCustomizeStringId().ifNotExist().create();
    schema.edgeLabel(EDGE_LABEL).sourceLabel(VERTX_LABEL).targetLabel(VERTX_LABEL).properties(PROPERTY_KEY).ifNotExist().create();
    GraphManager graph = client().graph();
    Vertex vA = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_A", PROPERTY_KEY, 1);
    Vertex vB = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_B", PROPERTY_KEY, 1);
    Vertex vC = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_C", PROPERTY_KEY, 1);
    Vertex vD = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_D", PROPERTY_KEY, 1);
    Vertex vE = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_E", PROPERTY_KEY, 1);
    vA.addEdge(EDGE_LABEL, vB, PROPERTY_KEY, 1);
    vA.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
    vB.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
    vC.addEdge(EDGE_LABEL, vD, PROPERTY_KEY, 1);
    vD.addEdge(EDGE_LABEL, vA, PROPERTY_KEY, 1);
    vD.addEdge(EDGE_LABEL, vE, PROPERTY_KEY, 1);
    vE.addEdge(EDGE_LABEL, vD, PROPERTY_KEY, 1);
    vE.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
}
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)

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