Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add yield clause for all ngql #971

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 43 additions & 35 deletions docs-2.0/2.quick-start/4.nebula-graph-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
GO [[<M> TO] <N> STEPS ] FROM <vertex_list>
OVER <edge_type_list> [{REVERSELY | BIDIRECT}]
[ WHERE <conditions> ]
[YIELD [DISTINCT] <return_list>]
YIELD [DISTINCT] <return_list>
[{SAMPLE <sample_list> | LIMIT <limit_list>}]
[| GROUP BY {col_name | expr | position} YIELD <col_name>]
[| ORDER BY <expression> [{ASC | DESC}]]
Expand All @@ -262,22 +262,22 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
```ngql
FETCH PROP ON {<tag_name>[, tag_name ...] | *}
<vid> [, vid ...]
[YIELD <return_list> [AS <alias>]];
YIELD <return_list> [AS <alias>];
```

* Fetch properties on edges:

```ngql
FETCH PROP ON <edge_type> <src_vid> -> <dst_vid>[@<rank>] [, <src_vid> -> <dst_vid> ...]
[YIELD <output>];
YIELD <output>;
```

* `LOOKUP`

```ngql
LOOKUP ON {<vertex_tag> | <edge_type>}
[WHERE <expression> [AND <expression> ...]]
[YIELD <return_list> [AS <alias>]];
YIELD <return_list> [AS <alias>];
```

* `MATCH`
Expand All @@ -291,12 +291,13 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
* Search for the players that the player with VID `player101` follows.

```ngql
nebula> GO FROM "player101" OVER follow;
nebula> GO FROM "player101" OVER follow YIELD id($$);
+-------------+
| follow._dst |
| id($$) |
+-------------+
| "player100" |
| "player102" |
| "player125" |
+-------------+
```

Expand All @@ -305,11 +306,12 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
```ngql
nebula> GO FROM "player101" OVER follow WHERE properties($$).age >= 35 \
YIELD properties($$).name AS Teammate, properties($$).age AS Age;
+--------------+-----+
| Teammate | Age |
+--------------+-----+
| "Tim Duncan" | 42 |
+--------------+-----+
+-----------------+-----+
| Teammate | Age |
+-----------------+-----+
| "Tim Duncan" | 42 |
| "Manu Ginobili" | 41 |
+-----------------+-----+
```

| Clause/Sign | Description |
Expand All @@ -329,7 +331,10 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
+-----------------+---------------------+
| Team | Player |
+-----------------+---------------------+
| "Spurs" | "Tim Duncan" |
| "Trail Blazers" | "LaMarcus Aldridge" |
| "Spurs" | "LaMarcus Aldridge" |
| "Spurs" | "Manu Ginobili" |
+-----------------+---------------------+
```

Expand All @@ -352,7 +357,10 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
+-----------------+---------------------+
| Team | Player |
+-----------------+---------------------+
| "Spurs" | "Tim Duncan" |
| "Trail Blazers" | "LaMarcus Aldridge" |
| "Spurs" | "LaMarcus Aldridge" |
| "Spurs" | "Manu Ginobili" |
+-----------------+---------------------+
```

Expand All @@ -361,12 +369,12 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
Use `FETCH`: Fetch the properties of the player with VID `player100`.

```ngql
nebula> FETCH PROP ON player "player100";
+----------------------------------------------------+
| vertices_ |
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+
nebula> FETCH PROP ON player "player100" YIELD properties(vertex);
+-------------------------------+
| properties(VERTEX) |
+-------------------------------+
| {age: 42, name: "Tim Duncan"} |
+-------------------------------+
```

!!! Note
Expand Down Expand Up @@ -413,25 +421,25 @@ Users can use the `UPDATE` or the `UPSERT` statements to update existing data.
```ngql
nebula> UPDATE VERTEX "player100" SET player.name = "Tim";

nebula> FETCH PROP ON player "player100";
+---------------------------------------------+
| vertices_ |
+---------------------------------------------+
| ("player100" :player{age: 42, name: "Tim"}) |
+---------------------------------------------+
nebula> FETCH PROP ON player "player100" YIELD properties(vertex);
+------------------------+
| properties(VERTEX) |
+------------------------+
| {age: 42, name: "Tim"} |
+------------------------+
```

* `UPDATE` the `degree` property of an edge and check the result with the `FETCH` statement.

```ngql
nebula> UPDATE EDGE "player101" -> "player100" OF follow SET degree = 96;

nebula> FETCH PROP ON follow "player101" -> "player100";
+----------------------------------------------------+
| edges_ |
+----------------------------------------------------+
| [:follow "player101"->"player100" @0 {degree: 96}] |
+----------------------------------------------------+
nebula> FETCH PROP ON follow "player101" -> "player100" YIELD properties(edge);
+------------------+
| properties(EDGE) |
+------------------+
| {degree: 96} |
+------------------+
```

* Insert a vertex with VID `player111` and `UPSERT` it.
Expand Down Expand Up @@ -518,7 +526,7 @@ Find the information of the vertex with the tag `player` and its value of the `n
This example creates the index `player_index_1` on the player name property.

```nGQL
nebula> CREATE TAG INDEX player_index_1 ON player(name(20));
nebula> CREATE TAG INDEX IF NOT EXISTS player_index_1 ON player(name(20));
```

This example rebuilds the index to make sure it takes effect on pre-existing data.
Expand All @@ -538,11 +546,11 @@ This example uses the `LOOKUP` statement to retrieve the vertex property.
```nGQL
nebula> LOOKUP ON player WHERE player.name == "Tony Parker" \
YIELD properties(vertex).name AS name, properties(vertex).age AS age;
+-------------+---------------+-----+
| VertexID | name | age |
+-------------+---------------+-----+
| "player101" | "Tony Parker" | 36 |
+-------------+---------------+-----+
+---------------+-----+
| name | age |
+---------------+-----+
| "Tony Parker" | 36 |
+---------------+-----+
```

This example uses the `MATCH` statement to retrieve the vertex property.
Expand Down
22 changes: 10 additions & 12 deletions docs-2.0/3.ngql-guide/10.tag-statements/6.delete-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,25 @@ DELETE TAG <tag_name_list> FROM <VID>;
nebula> CREATE TAG IF NOT EXISTS test1(p1 string, p2 int);
nebula> CREATE TAG IF NOT EXISTS test2(p3 string, p4 int);
nebula> INSERT VERTEX test1(p1, p2),test2(p3, p4) VALUES "test":("123", 1, "456", 2);
nebula> FETCH PROP ON * "test";
nebula> FETCH PROP ON * "test" YIELD vertex AS v;
+------------------------------------------------------------+
| vertices_ |
| v |
+------------------------------------------------------------+
| ("test" :test2{p3: "456", p4: 2} :test1{p1: "123", p2: 1}) |
| ("test" :test1{p1: "123", p2: 1} :test2{p3: "456", p4: 2}) |
+------------------------------------------------------------+

nebula> DELETE TAG test1 FROM "test";
nebula> FETCH PROP ON * "test";
nebula> FETCH PROP ON * "test" YIELD vertex AS v;
+-----------------------------------+
| vertices_ |
| v |
+-----------------------------------+
| ("test" :test2{p3: "456", p4: 2}) |
+-----------------------------------+

nebula> DELETE TAG * FROM "test";
nebula> FETCH PROP ON * "test";
+-----------+
| vertices_ |
+-----------+
+-----------+
nebula> FETCH PROP ON * "test" YIELD vertex AS v;
+---+
| v |
+---+
+---+
```

!!! Compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ nebula> MATCH (v:shareholder) RETURN v;
| ("player100" :player{age: 42, name: "Tim Duncan"} :shareholder{}) |
| ("player101" :player{age: 36, name: "Tony Parker"} :shareholder{}) |
+--------------------------------------------------------------------+
nebula> LOOKUP ON shareholder;

nebula> LOOKUP ON shareholder YIELD id(vertex);
+-------------+
| VertexID |
| id(VERTEX) |
+-------------+
| "player100" |
| "player101" |
+-------------+

//In this example, the "player100" is no longer a shareholder.
nebula> DELETE TAG shareholder FROM "player100";
nebula> LOOKUP ON shareholder;
nebula> LOOKUP ON shareholder YIELD id(vertex);
+-------------+
| VertexID |
| id(VERTEX) |
+-------------+
| "player101" |
+-------------+
Expand Down
48 changes: 24 additions & 24 deletions docs-2.0/3.ngql-guide/12.vertex-statements/1.insert-vertex.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ A vertex can be inserted/written with new values multiple times. Only the last w
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n2", 13);
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n3", 14);
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n4", 15);
nebula> FETCH PROP ON t2 "11";
+---------------------------------+
| vertices_ |
+---------------------------------+
| ("11" :t2{age: 15, name: "n4"}) |
+---------------------------------+
nebula> FETCH PROP ON t2 "11" YIELD properties(vertex);
+-----------------------+
| properties(VERTEX) |
+-----------------------+
| {age: 15, name: "n4"} |
+-----------------------+
```

```ngql
Expand All @@ -96,21 +96,21 @@ nebula> INSERT VERTEX t5(p1, p2, p3) VALUES "002":(NULL, 4, 5);

# In the following example, the value of p3 is the default NULL.
nebula> INSERT VERTEX t5(p1, p2) VALUES "003":("cd", 5);
nebula> FETCH PROP ON t5 "003";
+--------------------------------------------+
| vertices_ |
+--------------------------------------------+
| ("003" :t5{p1: "cd", p2: 5, p3: __NULL__}) |
+--------------------------------------------+
nebula> FETCH PROP ON t5 "003" YIELD properties(vertex);
+---------------------------------+
| properties(VERTEX) |
+---------------------------------+
| {p1: "cd", p2: 5, p3: __NULL__} |
+---------------------------------+

# In the following example, the allowed maximum length of p1 is 5.
nebula> INSERT VERTEX t5(p1, p2) VALUES "004":("shalalalala", 4);
nebula> FETCH PROP on t5 "004";
+-----------------------------------------------+
| vertices_ |
+-----------------------------------------------+
| ("004" :t5{p1: "shala", p2: 4, p3: __NULL__}) |
+-----------------------------------------------+
nebula> FETCH PROP on t5 "004" YIELD properties(vertex);
+------------------------------------+
| properties(VERTEX) |
+------------------------------------+
| {p1: "shala", p2: 4, p3: __NULL__} |
+------------------------------------+
```

If you insert a vertex that already exists with `IF NOT EXISTS`, there will be no modification.
Expand All @@ -120,10 +120,10 @@ If you insert a vertex that already exists with `IF NOT EXISTS`, there will be n
nebula> INSERT VERTEX t2 (name, age) VALUES "1":("n2", 13);
# Modify vertex "1" with IF NOT EXISTS. But there will be no modification as vertex "1" already exists.
nebula> INSERT VERTEX IF NOT EXISTS t2 (name, age) VALUES "1":("n3", 14);
nebula> FETCH PROP ON t2 "1";
+--------------------------------+
| vertices_ |
+--------------------------------+
| ("1" :t2{age: 13, name: "n2"}) |
+--------------------------------+
nebula> FETCH PROP ON t2 "1" YIELD properties(vertex);
+-----------------------+
| properties(VERTEX) |
+-----------------------+
| {age: 13, name: "n2"} |
+-----------------------+
```
12 changes: 6 additions & 6 deletions docs-2.0/3.ngql-guide/12.vertex-statements/2.update-vertex.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ SET <update_prop>

```ngql
// This query checks the properties of vertex "player101".
nebula> FETCH PROP ON player "player101";
+-----------------------------------------------------+
| vertices_ |
+-----------------------------------------------------+
| ("player101" :player{age: 36, name: "Tony Parker"}) |
+-----------------------------------------------------+
nebula> FETCH PROP ON player "player101" YIELD properties(vertex);
+--------------------------------+
| properties(VERTEX) |
+--------------------------------+
| {age: 36, name: "Tony Parker"} |
+--------------------------------+

// This query updates the age property and returns name and the new age.
nebula> UPDATE VERTEX ON player "player101" \
Expand Down
38 changes: 19 additions & 19 deletions docs-2.0/3.ngql-guide/12.vertex-statements/3.upsert-vertex.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ Here are some examples:

```ngql
// This query checks if the following three vertices exist. The result "Empty set" indicates that the vertices do not exist.
nebula> FETCH PROP ON * "player666", "player667", "player668";
+-----------+
| vertices_ |
+-----------+
+-----------+
nebula> FETCH PROP ON * "player666", "player667", "player668" YIELD properties(vertex);
+--------------------+
| properties(VERTEX) |
+--------------------+
+--------------------+
Empty set

nebula> UPSERT VERTEX ON player "player666" \
Expand Down Expand Up @@ -124,12 +124,12 @@ nebula> UPSERT VERTEX ON player_with_default "player101" \
If the vertex exists and the `WHEN` conditions are met, the vertex is updated.

```ngql
nebula> FETCH PROP ON player "player101";
+-----------------------------------------------------+
| vertices_ |
+-----------------------------------------------------+
| ("player101" :player{age: 42, name: "Tony Parker"}) |
+-----------------------------------------------------+
nebula> FETCH PROP ON player "player101" YIELD properties(vertex);
+--------------------------------+
| properties(VERTEX) |
+--------------------------------+
| {age: 36, name: "Tony Parker"} |
+--------------------------------+

nebula> UPSERT VERTEX ON player "player101" \
SET age = age + 2 \
Expand All @@ -138,19 +138,19 @@ nebula> UPSERT VERTEX ON player "player101" \
+---------------+-----+
| Name | Age |
+---------------+-----+
| "Tony Parker" | 44 |
| "Tony Parker" | 38 |
+---------------+-----+
```

If the vertex exists and the `WHEN` conditions are not met, the update does not take effect.

```ngql
nebula> FETCH PROP ON player "player101";
+-----------------------------------------------------+
| vertices_ |
+-----------------------------------------------------+
| ("player101" :player{age: 44, name: "Tony Parker"}) |
+-----------------------------------------------------+
nebula> FETCH PROP ON player "player101" YIELD properties(vertex);
+--------------------------------+
| properties(VERTEX) |
+--------------------------------+
| {age: 38, name: "Tony Parker"} |
+--------------------------------+

nebula> UPSERT VERTEX ON player "player101" \
SET age = age + 2 \
Expand All @@ -159,6 +159,6 @@ nebula> UPSERT VERTEX ON player "player101" \
+---------------+-----+
| Name | Age |
+---------------+-----+
| "Tony Parker" | 44 |
| "Tony Parker" | 38 |
+---------------+-----+
```
Loading