Skip to content

Commit

Permalink
[doc]add if not exists (vesoft-inc#1407)
Browse files Browse the repository at this point in the history
* add if not exist

* comments

* jie

* wum

* update query syntax
  • Loading branch information
amber-moe authored and dutor committed Dec 18, 2019
1 parent a58fee9 commit 008c297
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# CREATE SPACE 语法

```ngql
CREATE SPACE space_name
(space_option,...)
space_option:
option_name = value
CREATE SPACE [IF NOT EXISTS] <space_name>
[(partition_num = <part_num>, replica_factor = <raft_copy>)]
```

以上语句用于创建一个新的图空间。不同的图空间是物理隔离的。

## IF NOT EXISTS

创建图空间可使用 `IF NOT EXISTS` 关键字,这个关键字会自动检测对应的图空间是否存在,如果不存在则创建新的,如果存在则直接返回。

**注意:** 这里判断图空间是否存在只是比较图空间的名字(不包括属性)。

## Space Name 图空间名

* **space_name**

图空间的名称在集群中标明了一个唯一的空间。命名规则详见 [Schema Object Names](../../3.language-structure/schema-object-names.md)

### Space Options 图空间选项
## 自定义图空间选项

在创建图空间的时候,可以传入自定义选项。选项名称 _option_name_ 可以是以下任何一个
在创建图空间的时候,可以传入如下两个自定义选项

* _partition_num_

Expand All @@ -30,7 +33,7 @@ space_option:

如果没有自定义选项,**Nebula Graph** 会使用默认的值(partition_number 和 replica_factor)来创建图空间。

### 示例
## 示例

```ngql
nebula> CREATE SPACE my_space_1; -- 使用默认选项创建图空间
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
# CREATE TAG / EDGE 语法

```ngql
CREATE {TAG | EDGE} tag_name|edge_name
(create_definition, ...)
CREATE {TAG <tag_name> | EDGE <edge_name>} [IF NOT EXISTS]
([<create_definition>, ...])
[tag_edge_options]
create_definition:
prop_name data_type
<create_definition> ::=
<prop_name> <data_type>
tag_edge_options:
option [, option ...]
<tag_edge_options> ::=
<option> [, <option> ...]
option:
TTL_DURATION [=] ttl_duration
| TTL_COL [=] prop_name
<option> ::=
TTL_DURATION [=] <ttl_duration>
| TTL_COL [=] <prop_name>
| DEFAULT <default_value>
```

**Nebula Graph** 的图结构由带有属性的 tags 和 edges 组成。`CREATE TAG` 使用一个给定的名称创建一个新的 tag。`CREATE EDGE` 则创建一个新的 edge type。

`CREATE TAG/EDGE` 语法有一些特点,在如下分块中将对这些特点进行讨论:

## IF NOT EXISTS

创建 tag 或 edge 可使用 `IF NOT EXISTS` 关键字,这个关键字会自动检测对应的 tag 或 edge 是否存在,如果不存在则创建新的,如果存在则直接返回。

**注意:** 这里判断 tag 或 edge 是否存在只是比较 tag 或 edge 的名字(不包括属性)。

## Tag 名称和 Edge Type 名称

* **tag_name 和 edge_name**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# Create Space Syntax

```ngql
CREATE SPACE space_name
(space_option,...)
space_option:
option_name = value
CREATE SPACE [IF NOT EXISTS] <space_name>
[(partition_num = <part_num>, replica_factor = <raft_copy>)]
```

This statement creates a new space with the given name. SPACE is a region that provides physically isolated graphs in **Nebula Graph**. An error occurs if the database exists.

## IF NOT EXISTS

You can use the `If NOT EXISTS` keywords when creating spaces. This keyword automatically detects if the corresponding space exists. If it does not exist, a new one is created. Otherwise, no space is created.

**Note:** The space existence detection here only compares the space name (excluding properties).

## Space Name

* **space_name**

The name uniquely identifies the space in a cluster. The rules for the naming are given in [Schema Object Names](../../3.language-structure/schema-object-names.md)

### Space Options
## Customized Space Options

When creating a space, options can be given. An _option_name_ can be any of the following:
When creating a space, the following two customized options can be given:

* _partition_num_

Expand All @@ -30,7 +33,7 @@ When creating a space, options can be given. An _option_name_ can be any of the

However, if no option is given, **Nebula Graph** will create the space with the default partition number and replica factor.

### Example
## Example

```ngql
nebula> CREATE SPACE my_space_1; -- create space with default partition number and replica factor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Create TAG / EDGE Syntax

```ngql
CREATE {TAG | EDGE} <tag_name> | <edge_name>
(<create_definition>, ...)
CREATE {TAG <tag_name> | EDGE <edge_name>} [IF NOT EXISTS]
([<create_definition>, ...])
[tag_edge_options]
<create_definition> ::=
Expand All @@ -21,6 +21,12 @@ CREATE {TAG | EDGE} <tag_name> | <edge_name>

The features of this syntax are described in the following sections:

## IF NOT EXISTS

You can use the `If NOT EXISTS` keywords when creating tags or edges. This keyword automatically detects if the corresponding tag or edge exists. If it does not exist, a new one is created. Otherwise, no tag or edge is created.

**Note:** The tag or edge existence detection here only compares the tag or edge name (excluding properties).

## Tag Name and Edge Type Name

* **tag_name and edge_name**
Expand Down

0 comments on commit 008c297

Please sign in to comment.