Skip to content
Permalink
Browse files
HugeGraph-1119: Add code type tag
Change-Id: I8b89ba4426139e6f0311bf73a8c067911a88996d
  • Loading branch information
Linary committed Apr 26, 2018
1 parent 1b3a4d8 commit 15215a308455318a281068983be75e1df1c63162
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 245 deletions.
@@ -9,8 +9,6 @@ HugeGraph可以支持多用户并行操作,用户可以输入Gremlin查询语

本系统的主要应用场景是解决百度安全事业部所面对的金融反欺诈、威胁情报、黑产打击等业务的图数据存储和建模分析需求,在此基础上逐步扩展并支持更多的应用。

随着系统逐步成熟稳定,HugeGraph最终可以以开源的方式捐赠给开源基金会,填补国内图数据库市场空白。

### Features

HugeGraph是一款离线环境下,面向分析型,支持批量操作的图数据库系统,它能够与大数据平台无缝集成。
@@ -4,10 +4,10 @@

## Quickstart
* [Install HugeGraph](quickstart/hugeserver.md)
* [Load data With HugeLoader](quickstart/hugeloader.md)
* [Load data with HugeLoader](quickstart/hugeloader.md)
* [Display with HugeStudio](quickstart/hugestudio.md)
* [Develop With HugeClient](quickstart/hugeclient.md)
* [Analysis With HugeSpark](quickstart/hugespark.md)
* [Develop with HugeClient](quickstart/hugeclient.md)
* [Analysis with HugeSpark](quickstart/hugespark.md)

## Guides
* [Architecture Overview](guides/architectural.md)
@@ -13,7 +13,7 @@ Gremlin-Console是由Tinkerpop自己开发的一个交互式客户端,用户

在script目录下有一个示例脚本:example.groovy

```
```groovy
import com.baidu.hugegraph.HugeFactory
import com.baidu.hugegraph.dist.RegisterUtil
import org.apache.tinkerpop.gremlin.structure.T
@@ -71,7 +71,7 @@ System.out.println(">>>> query all edges: size=" + g.E().toList().size());

下面进入gremlin-console,并传入该脚本令其执行:

```
```bash
bin/gremlin-console.sh scripts/example.groovy
objc[5038]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10137a4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x102bbb4e0). One of the two will be used. Which one is undefined.
@@ -91,7 +91,7 @@ plugin activated: tinkerpop.tinkergraph

可以看到,插入了6个顶点、6条边,并查询出来了。进入console之后,还可继续输入groovy语句对图做操作:

```
```groovy
gremlin> g.V()
==>v[2:ripple]
==>v[1:vadas]
@@ -116,7 +116,7 @@ gremlin> g.E()

*注意:将连接方式修改为WebSocket后,HugeClient、HugeLoader、HugeStudio等配套工具都不能使用了。*

```
```yaml
# vim conf/gremlin-server.yaml
host: 127.0.0.1
port: 8182
@@ -193,7 +193,7 @@ ssl: {

然后进入gremlin-console

```
```bash
bin/gremlin-console.sh
objc[5761]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10ec584c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10ecdc4e0). One of the two will be used. Which one is undefined.
@@ -208,7 +208,7 @@ plugin activated: tinkerpop.tinkergraph

连接server,需在配置文件中指定连接参数,在conf目录下有一个默认的remote.yaml

```
```yaml
# cat conf/remote.yaml
hosts: [localhost]
port: 8182
@@ -221,7 +221,7 @@ serializer: {
}
```

```
```groovy
gremlin> :remote connect tinkerpop.server conf/remote.yaml
2018-01-15 15:30:31 11528 [main] [INFO ] org.apache.tinkerpop.gremlin.driver.Connection [] - Created new connection for ws://localhost:8182/gremlin
2018-01-15 15:30:31 11538 [main] [INFO ] org.apache.tinkerpop.gremlin.driver.Connection [] - Created new connection for ws://localhost:8182/gremlin
@@ -230,7 +230,8 @@ gremlin> :remote connect tinkerpop.server conf/remote.yaml
```

连接成功之后,在console的上下文中能使用的变量只有hugegraph和hugegraph1两个图对象(在gremlin-server.yaml中配置),如果想拥有更多的变量,可以在`scripts/empty-sample.groovy`中添加,如:
```

```groovy
import org.apache.tinkerpop.gremlin.server.util.LifeCycleHook
// an init script that returns a Map allows explicit setting of global bindings.
@@ -256,7 +257,8 @@ g = hugegraph.traversal()
这样在console中便可以直接使用schema和g这两个对象,做元数据的管理和图的查询了。

不定义了也没关系,因为所有的对象都可以通过graph获得,例如:
```

```groovy
gremlin> :> hugegraph.traversal().V()
==>v[2:ripple]
==>v[1:vadas]
@@ -270,7 +272,7 @@ gremlin> :> hugegraph.traversal().V()

还可以把多条语句放在一个字符串变量中,然后一次性发给server:

```
```groovy
gremlin> script = """
graph = hugegraph;
marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing");
@@ -10,7 +10,7 @@ HugeClient 是操作 graph 的总入口,用户必须先创建出 HugeClient

目前 HugeClient 只允许连接服务端已存在的图,无法自定义图进行创建。其创建方法如下:

```
```java
// HugeGraph Server地址:"http://localhost:8080"
// 图的名称:"hugegraph"
HugeClient hugeClient = new HugeClient("http://localhost:8080", "hugegraph");
@@ -26,8 +26,8 @@ SchemaManager 用于管理 HugeGraph 中的四种元数据,分别是PropertyKe

用户可使用如下方法获得SchemaManager对象:

```
schema = hugeClient.schema()
```java
SchemaManager schema = hugeClient.schema()
```

下面分别对三种元数据的定义过程进行介绍。
@@ -78,21 +78,21 @@ userdata(String key, Object value) | The same key, the latter will cover the for

##### 2.2.2 创建 PropertyKey

```
```java
schema.propertyKey("name").asText().valueSet().ifNotExist().create()
```

- ifNotExist():为 create 添加判断机制,若当前 PropertyKey 已经存在则不再创建,否则创建该属性。若不添加判断,在 properkey 已存在的情况下会抛出异常信息,下同,不再赘述。

##### 2.2.3 删除 PropertyKey

```
```java
schema.propertyKey("name").remove()
```

##### 2.2.4 查询 PropertyKey

```
```java
// 获取PropertyKey对象
schema.getPropertyKey("name")
@@ -168,7 +168,7 @@ userData(String key, Object value) | The same key, the latter will cover the for

##### 2.3.2 创建 VertexLabel

```
```java
// 使用 Automatic 的 Id 策略
schema.vertexLabel("person").properties("name", "age").ifNotExist().create();
schema.vertexLabel("person").useAutomaticId().properties("name", "age").primaryKeys("name").ifNotExist().create();
@@ -187,19 +187,19 @@ schema.vertexLabel("person").usePrimaryKeyId().properties("name", "age").primary

VertexLabel 是可以追加约束的,不过仅限 properties 和 nullableKeys,而且追加的属性也必须添加到 nullableKeys 集合中。

```
```java
schema.vertexLabel("person").properties("price").nullableKeys("price").append();
```

##### 2.3.4 删除 VertexLabel

```
```java
schema.vertexLabel("person").remove();
```

##### 2.3.5 查询 VertexLabel

```
```java
// 获取VertexLabel对象
schema.getVertexLabel("name")
@@ -268,26 +268,26 @@ userData(String key, Object value) | The same key, the latter will cover the for

##### 2.4.2 创建 EdgeLabel

```
```java
schema.edgeLabel("knows").link("person", "person").properties("date").ifNotExist().create();
schema.edgeLabel("created").multiTimes().link("person", "software").properties("date").sortKeys("date").ifNotExist().create();
```

##### 2.4.3 追加 EdgeLabel

```
```java
schema.edgeLabel("knows").properties("price").nullableKeys("price").append();
```

##### 2.4.4 删除 EdgeLabel

```
```java
schema.edgeLabel("knows").remove();
```

##### 2.4.5 查询 EdgeLabel

```
```java
// 获取EdgeLabel对象
schema.getEdgeLabel("knows")
@@ -340,20 +340,20 @@ range() | Range | supports range search for numeric types

##### 2.5.2 创建 IndexLabel

```
```java
schema.indexLabel("personByAge").onV("person").by("age").range().ifNotExist().create();
schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create();
```

##### 2.5.3 删除 IndexLabel

```
```java
schema.indexLabel("personByAge").remove()
```

##### 2.5.4 查询 IndexLabel

```
```java
// 获取IndexLabel对象
schema.getIndexLabel("personByAge")
@@ -371,7 +371,7 @@ schema.getIndexLabel("personByAge").name()

顶点是构成图的最基本元素,一个图中可以有非常多的顶点。下面给出一个添加顶点的例子:

```
```java
Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29);
Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328);
```
@@ -390,7 +390,7 @@ Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java",

有了点,还需要边才能构成完整的图。下面给出一个添加边的例子:

```
```java
Edge knows1 = marko.addEdge("knows", vadas, "city", "Beijing");
```

0 comments on commit 15215a3

Please sign in to comment.