HugeGraph中Gremlin的核心语法 郝伟 2021/05/20 [TOC]

1. 简介

1.1. schema 操作

1.1.1. create

2. 数据类型

参考:HugeGraph图数据库概念详解

2.1. 基本数据类型

asText(),字符串类型,是默认值
asInt(),整型
asDate(),日期类型
asUuid(),UUID类型
asBoolean(),布尔型
asByte(),字节型
asBlob(),字节数组型
asDouble(),双精度浮点型
asFloat(),单精度浮点型
asLong(),长整型

2.2. 集合数据类型

集合类型表示变量的个数和组织方式,具体有以下三种值:

  • valueSingle(),值是单值类型,只有1个值(默认值);
  • valueList(),值是列表类型,有序且可以重复;
  • valueSet(),值是集合类型,无序且不可以重复。

2.2.1. 示例

// 创建基本属性
graph.schema().propertyKey("name").asText().ifNotExist().create()
graph.schema().propertyKey("age").asInt().ifNotExist().create()
graph.schema().propertyKey("city").asText().ifNotExist().create()
graph.schema().propertyKey("lang").asText().ifNotExist().create()
graph.schema().propertyKey("date").asText().ifNotExist().create()
graph.schema().propertyKey("price").asInt().ifNotExist().create()

// 创建person节点标签和属性
person = graph.schema().vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create()

// 添加person顶点数据
marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing")
vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong")
josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city", "Beijing")
peter = graph.addVertex(T.label, "person","name", "peter", "age", 29, "city", "Shanghai")

// 添加software节点标签和属性
software = graph.schema().vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create()

// 创建software顶点
lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328)
ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang", "java", "price", 199)

// 创建knows边
knows = graph.schema().edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date").ifNotExist().create()
marko.addEdge("knows", vadas, "date", "20160110")
marko.addEdge("knows", josh, "date", "20130220")
marko.addEdge("created", lop, "date", "20171210", "city", "Shanghai")

// 创建created边
created = graph.schema().edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "city").ifNotExist().create()
josh.addEdge("created", ripple, "date", "20151010", "city", "Beijing")
josh.addEdge("created", lop, "date", "20171210", "city", "Beijing")
peter.addEdge("created", lop, "date", "20171210", "city", "Beijing")

2.3. 注意事项

关于创建可空节点属性

graph.schema().vertexLabel("person").properties("namex").ifNotExist().append();
graph.schema().vertexLabel("person").nullableKeys("namex").ifNotExist().append();

// 以下代码都可以执行,但是没有作用 graph.schema().vertexLabel("person").remove() graph.schema().vertexLabel("person").properties("namex").remove() graph.schema().vertexLabel("person").properties().remove()

results matching ""

    No results matching ""