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

yield command changes for all docs #817

Merged
merged 8 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ After a query is sent to Graph Service, it will be processed by the following fo

After receiving a request, the statements will be parsed by the Parser composed of Flex (lexical analysis tool) and Bison (syntax analysis tool), and its corresponding AST will be generated. Statements will be directly intercepted in this stage because of its invalid syntax.

For example, the structure of the AST of `GO FROM "Tim" OVER like WHERE like.likeness > 8.0 YIELD like._dst` is shown in the following picture.
For example, the structure of the AST of `GO FROM "Tim" OVER like WHERE properties(edge).likeness > 8.0 YIELD dst(edge)` is shown in the following picture.

![AST](https://docs-cdn.nebula-graph.com.cn/docs-2.0/1.introduction/2.nebula-graph-architecture/parser-ast-tree.png)

Expand All @@ -38,7 +38,7 @@ Validator performs a series of validations on the AST. It mainly works on these

Validator will verify whether the cited variable exists or not, or whether the cited property is variable or not.

For composite statements, like `$var = GO FROM "Tim" OVER like YIELD like._dst AS ID; GO FROM $var.ID OVER serve YIELD serve._dst`, Validator verifies first to see if `var` is defined, and then to check if the `ID` property is attached to the `var` variable.
For composite statements, like `$var = GO FROM "Tim" OVER like YIELD dst(edge) AS ID; GO FROM $var.ID OVER serve YIELD dst(edge)`, Validator verifies first to see if `var` is defined, and then to check if the `ID` property is attached to the `var` variable.

- Validating type inference

Expand All @@ -50,13 +50,13 @@ Validator performs a series of validations on the AST. It mainly works on these

Validator needs to verify all the Schema that involves `*` when verifying the clause if there is a `*` in the statement.

Take a statement like `GO FROM "Tim" OVER * YIELD like._dst, like.likeness, serve._dst` as an example. When verifying the `OVER` clause, Validator needs to verify all the edge types. If the edge type includes `like` and `serve`, the statement would be `GO FROM "Tim" OVER like,serve YIELD like._dst, like.likeness, serve._dst`.
Take a statement like `GO FROM "Tim" OVER * YIELD dst(edge), properties(edge).likeness, dst(edge)` as an example. When verifying the `OVER` clause, Validator needs to verify all the edge types. If the edge type includes `like` and `serve`, the statement would be `GO FROM "Tim" OVER like,serve YIELD dst(edge), properties(edge).likeness, dst(edge)`.

- Validating input and output

Validator will check the consistency of the clauses before and after the `|`.

In the statement `GO FROM "Tim" OVER like YIELD like._dst AS ID | GO FROM $-.ID OVER serve YIELD serve._dst`, Validator will verify whether `$-.ID` is defined in the clause before the `|`.
In the statement `GO FROM "Tim" OVER like YIELD dst(edge) AS ID | GO FROM $-.ID OVER serve YIELD dst(edge)`, Validator will verify whether `$-.ID` is defined in the clause before the `|`.

When the validation succeeds, an execution plan will be generated. Its data structure will be stored in the `src/planner` directory.

Expand Down
2 changes: 1 addition & 1 deletion docs-2.0/14.client/4.nebula-java-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ try {
ResultSet resp = session.execute(insertEdges);

// query
String query = "GO FROM \"Bob\" OVER like " + "YIELD $$.person.name, $$.person.age, like.likeness";
String query = "GO FROM \"Bob\" OVER like " + "YIELD properties($$).name, properties($$).age, properties(edge).likeness";
ResultSet resp = session.execute(query);
printResult(resp);
}finally {
Expand Down
85 changes: 47 additions & 38 deletions docs-2.0/2.quick-start/4.nebula-graph-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,34 +269,37 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi

```ngql
GO [[<M> TO] <N> STEPS ] FROM <vertex_list>
OVER <edge_type_list> [REVERSELY] [BIDIRECT]
[WHERE <expression> [AND | OR expression ...])]
YIELD [DISTINCT] <return_list>;
OVER <edge_type_list> [{REVERSELY | BIDIRECT}]
[ WHERE <conditions> ]
[YIELD [DISTINCT] <return_list>]
[| GROUP BY {col_name | expr | position} YIELD <col_name>]
[| ORDER BY <expression> [{ASC | DESC}]]
[| LIMIT [<offset_value>,] <number_rows>];
```

* `FETCH`

* Fetch properties on tags:

```ngql
FETCH PROP ON {<tag_name> | <tag_name_list> | *} <vid_list>
[YIELD [DISTINCT] <return_list>];
FETCH PROP ON {<tag_name>[, tag_name ...] | *}
<vid> [, vid ...]
[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 [DISTINCT] <return_list>];
FETCH PROP ON <edge_type> <src_vid> -> <dst_vid>[@<rank>] [, <src_vid> -> <dst_vid> ...]
[YIELD <output>];
```

* `LOOKUP`

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

* `MATCH`
Expand Down Expand Up @@ -324,14 +327,15 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
* Filter the players that the player with VID `player100` follows whose age is equal to or greater than 35. Rename the corresponding columns in the results with `Teammate` and `Age`.

```ngql
nebula> GO FROM "player100" OVER follow WHERE $$.player.age >= 35 \
YIELD $$.player.name AS Teammate, $$.player.age AS Age;
+---------------+-----+
| Teammate | Age |
+---------------+-----+
| "Tony Parker" | 36 |
+---------------+-----+
Got 1 rows (time spent 8206/9335 us)
nebula> GO FROM "player100" OVER follow WHERE properties($$).age >= 35 \
YIELD properties($$).name AS Teammate, properties($$).age AS Age;
+-----------------+-----+
| Teammate | Age |
+-----------------+-----+
| "Tony Parker" | 36 |
+-----------------+-----+
| "Manu Ginobili" | 41 |
+-----------------+-----+
```

|Clause/Sign|Description|
Expand All @@ -345,15 +349,18 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
* With a pipe:

```ngql
nebula> GO FROM "player100" OVER follow YIELD follow._dst AS id | \
GO FROM $-.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+-----------+---------------+
| Team | Player |
+-----------+---------------+
| "Nuggets" | "Tony Parker" |
+-----------+---------------+
Got 1 rows (time spent 5055/8203 us)
nebula> GO FROM "player100" OVER follow YIELD dst(edge) AS id | \
GO FROM $-.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```

|Clause/Sign|Description|
Expand All @@ -369,15 +376,18 @@ Users can use the `INSERT` statement to insert vertices or edges based on existi
Once a composite statement is submitted to the server as a whole, the life cycle of the temporary variables in the statement ends.

```ngql
nebula> $var = GO FROM "player100" OVER follow YIELD follow._dst AS id; \
GO FROM $var.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+---------+-------------+
| Team | Player |
+---------+-------------+
| Nuggets | Tony Parker |
+---------+-------------+
Got 1 rows (time spent 3103/3711 us)
nebula> $var = GO FROM "player100" OVER follow YIELD dst(edge) AS id; \
GO FROM $var.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```

### Example of `FETCH` statement
Expand All @@ -391,7 +401,6 @@ nebula> FETCH PROP ON player "player100";
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+
Got 1 rows (time spent 2006/2406 us)
```

!!! Note
Expand Down
6 changes: 3 additions & 3 deletions docs-2.0/3.ngql-guide/1.nGQL-overview/1.overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ Feature: Comparison of where clause
When profiling query:
"""
GO FROM "player100" OVER follow
WHERE follow.degree IN [v IN [95,99] WHERE v > 0]
YIELD follow._dst, follow.degree
WHERE properties(edge).degree IN [v IN [95,99] WHERE v > 0]
YIELD dst(edge), properties(edge).degree
"""
Then the result should be, in any order:
| follow._dst | follow.degree |
Expand All @@ -163,7 +163,7 @@ Feature: Comparison of where clause
And the execution plan should be:
| id | name | dependencies | operator info |
| 0 | Project | 1 | |
| 1 | GetNeighbors | 2 | {"filter": "(follow.degree IN [v IN [95,99] WHERE (v>0)])"} |
| 1 | GetNeighbors | 2 | {"filter": "(properties(edge).degree IN [v IN [95,99] WHERE (v>0)])"} |
| 2 | Start | | |
```

Expand Down
22 changes: 11 additions & 11 deletions docs-2.0/3.ngql-guide/1.nGQL-overview/ngql-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ nGQL does not have strict formatting requirements, but creating nGQL statements
Not recommended:

```ngql
GO FROM "player100" OVER follow REVERSELY YIELD follow._dst AS id;
GO FROM "player100" OVER follow REVERSELY YIELD src(edge) AS id;
```

Recommended:

```ngql
GO FROM "player100" \
OVER follow REVERSELY \
YIELD follow._dst AS id;
YIELD src(edge) AS id;
```

2. Start a new line to write different statements in a composite statement.

Not recommended:

```ngql
GO FROM "player100" OVER follow REVERSELY YIELD follow._dst AS id | GO FROM $-.id \
OVER serve WHERE $^.player.age > 20 YIELD $^.player.name AS FriendOf, $$.team.name AS Team;
GO FROM "player100" OVER follow REVERSELY YIELD src(edge) AS id | GO FROM $-.id \
OVER serve WHERE properties($^).age > 20 YIELD properties($^).name AS FriendOf, properties($$).name AS Team;
```

Recommended:

```ngql
GO FROM "player100" \
OVER follow REVERSELY \
YIELD follow._dst AS id | \
YIELD src(edge) AS id | \
GO FROM $-.id OVER serve \
WHERE $^.player.age > 20 \
YIELD $^.player.name AS FriendOf, $$.team.name AS Team;
WHERE properties($^).age > 20 \
YIELD properties($^).name AS FriendOf, properties($$).name AS Team;
```

3. If the clause exceeds 80 characters, start a new line at the appropriate place.
Expand Down Expand Up @@ -218,21 +218,21 @@ The strings should be surrounded by double quotes.
```ngql
GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id; | \
YIELD dst(edge) AS id; | \
GO FROM $-.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```

Supported:

```ngql
GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id | \
YIELD dst(edge) AS id | \
GO FROM $-.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```

3. In a composite statement that contains user-defined variables, use an English semicolon to end the statements that define the variables. If you do not follow the rules to add a semicolon or use a pipe to end the composite statement, the execution will fail.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nebula> DELETE VERTEX "team1";
This query shows that you can use `DELETE VERTEX` together with pipe to delete vertices.

```ngql
nebula> GO FROM "player100" OVER serve WHERE serve.start_year == "2021" YIELD serve._dst AS id | DELETE VERTEX $-.id;
nebula> GO FROM "player100" OVER serve WHERE properties(edge).start_year == "2021" YIELD dst(edge) AS id | DELETE VERTEX $-.id;
```

## Delete the process and the related edges
Expand Down
2 changes: 1 addition & 1 deletion docs-2.0/3.ngql-guide/13.edge-statements/2.update-edge.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The following example checks the properties of the edge with the GO statement.
```ngql
nebula> GO FROM "player100" \
OVER serve \
YIELD serve.start_year, serve.end_year;
YIELD properties(edge).start_year, properties(edge).end_year;
+------------------+----------------+
| serve.start_year | serve.end_year |
+------------------+----------------+
Expand Down
4 changes: 2 additions & 2 deletions docs-2.0/3.ngql-guide/13.edge-statements/4.delete-edge.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The following example shows that you can use `DELETE EDGE` together with pipe op

```ngql
nebula> GO FROM "player100" OVER follow \
WHERE follow._dst == "team204" \
YIELD follow._src AS src, follow._dst AS dst, follow._rank AS rank \
WHERE dst(edge) == "team204" \
YIELD src(edge) AS src, dst(edge) AS dst, rank(edge) AS rank \
| DELETE EDGE follow $-.src->$-.dst @ $-.rank;
```
4 changes: 2 additions & 2 deletions docs-2.0/3.ngql-guide/3.data-types/6.list.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ nebula> RETURN size([1,2,3]);
+---------------+

# The following query calculates the elements in the list [92,90] and runs a conditional judgment in a where clause.
nebula> GO FROM "player100" OVER follow WHERE follow.degree NOT IN [x IN [92, 90] | x + $$.player.age] \
YIELD follow._dst AS id, follow.degree AS degree;
nebula> GO FROM "player100" OVER follow WHERE properties(edge).degree NOT IN [x IN [92, 90] | x + $$.player.age] \
YIELD dst(edge) AS id, properties(edge).degree AS degree;
+-------------+--------+
| id | degree |
+-------------+--------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ For example, a query is composed of three sub-queries: `A B C`, `A | B | C` or `

```ngql
# Connect multiple queries with pipes.
nebula> GO FROM "player100" OVER follow YIELD follow._dst AS id | \
GO FROM $-.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+---------+-------------+
| Team | Player |
+---------+-------------+
| Nuggets | Tony Parker |
+---------+-------------+
nebula> GO FROM "player100" OVER follow YIELD dst(edge) AS id | \
GO FROM $-.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ You can use user-defined variables in composite queries. Details about composite
## Example

```ngql
nebula> $var = GO FROM "player100" OVER follow YIELD follow._dst AS id; \
GO FROM $var.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+---------+-------------+
| Team | Player |
+---------+-------------+
| Nuggets | Tony Parker |
+---------+-------------+
nebula> $var = GO FROM "player100" OVER follow YIELD dst(edge) AS id; \
GO FROM $var.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Apart from the user-defined edge property, there are four built-in properties in
The following query returns the `name` property of the `player` tag on the source vertex and the `age` property of the `player` tag on the destination vertex.

```ngql
nebula> GO FROM "player100" OVER follow YIELD $^.player.name AS startName, $$.player.age AS endAge;
nebula> GO FROM "player100" OVER follow YIELD properties($^).name AS startName, properties($$).age AS endAge;
+--------------+--------+
| startName | endAge |
+--------------+--------+
Expand All @@ -74,7 +74,7 @@ nebula> GO FROM "player100" OVER follow YIELD $^.player.name AS startName, $$.pl
The following query returns the `degree` property of the edge type `follow`.

```ngql
nebula> GO FROM "player100" OVER follow YIELD follow.degree;
nebula> GO FROM "player100" OVER follow YIELD properties(edge).degree;
+---------------+
| follow.degree |
+---------------+
Expand All @@ -87,12 +87,12 @@ nebula> GO FROM "player100" OVER follow YIELD follow.degree;
The following query returns the source vertex, the destination vertex, the edge type, and the edge rank value of the edge type `follow`.

```ngql
nebula> GO FROM "player100" OVER follow YIELD follow._src, follow._dst, follow._type, follow._rank;
+-------------+-------------+--------------+--------------+
| follow._src | follow._dst | follow._type | follow._rank |
+-------------+-------------+--------------+--------------+
| "player100" | "player101" | 136 | 0 |
+-------------+-------------+--------------+--------------+
| "player100" | "player102" | 136 | 0 |
+-------------+-------------+--------------+--------------+
nebula> GO FROM "player100" OVER follow YIELD src(edge), dst(edge), type(edge), rank(edge);
+-------------+-------------+------------+------------+
| src(EDGE) | dst(EDGE) | type(EDGE) | rank(EDGE) |
+-------------+-------------+------------+------------+
| "player100" | "player101" | "follow" | 0 |
+-------------+-------------+------------+------------+
| "player100" | "player125" | "follow" | 0 |
+-------------+-------------+------------+------------+
```
Loading