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));
}
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());
}
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();
}
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();
}
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);
}
Aggregations