Skip to content

Commit

Permalink
update go and lookup (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
izhuxiaoqing committed Nov 2, 2021
1 parent ac82bad commit f16a4c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 66 deletions.
40 changes: 7 additions & 33 deletions docs-2.0/3.ngql-guide/7.general-query-statements/3.go.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ nebula> GO FROM "player100" OVER follow REVERSELY \
+---------------------+-----------------+
| FriendOf | Team |
+---------------------+-----------------+
| "Danny Green" | "Spurs" |
| "Danny Green" | "Cavaliers" |
+---------------------+-----------------+
| "Boris Diaw" | "Spurs" |
| "Boris Diaw" | "Jazz" |
| "Boris Diaw" | "Suns" |
...
# This MATCH query shares the same semantics with the preceding GO query.
Expand All @@ -164,34 +164,9 @@ nebula> MATCH (v)<-[e:follow]- (v2)-[e2:serve]->(v3) \
+---------------------+-----------------+
| FriendOf | Team |
+---------------------+-----------------+
| "Tony Parker" | "Spurs" |
| "Tony Parker" | "Hornets" |
+---------------------+-----------------+
...
```

```ngql
# The following example returns all the neighbor vertices of player 102.
nebula> GO FROM "player102" OVER follow \
YIELD dst(edge) AS both;
+-------------+
| both |
+-------------+
| "player100" |
| "player101" |
+-------------+
...
# This MATCH query shares the same semantics with the preceding GO query.
nebula> MATCH (v) -[e:follow]-(v2) \
WHERE id(v)== "player102" \
RETURN id(v2) AS both;
+-------------+
| both |
+-------------+
| "player101" |
| "player103" |
+-------------+
| "Boris Diaw" | "Spurs" |
| "Boris Diaw" | "Jazz" |
| "Boris Diaw" | "Suns" |
...
```

Expand All @@ -204,7 +179,6 @@ nebula> GO 1 TO 2 STEPS FROM "player100" OVER follow \
+-------------+
| "player101" |
| "player125" |
+-------------+
...
# This MATCH query shares the same semantics with the preceding GO query.
Expand All @@ -216,7 +190,7 @@ nebula> MATCH (v) -[e:follow*1..2]->(v2) \
+-------------+
| "player100" |
| "player102" |
+-------------+
...
```

```ngql
Expand Down
64 changes: 31 additions & 33 deletions docs-2.0/3.ngql-guide/7.general-query-statements/5.lookup.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ nebula> LOOKUP ON player \
+-------------+
| VertexID |
+-------------+
| "player144" |
| "player140" |
| "player144" |
+-------------+
nebula> LOOKUP ON player \
Expand All @@ -109,20 +109,20 @@ nebula> LOOKUP ON player \
+-------------+-------------------------+------------------------+
| VertexID | properties(VERTEX).name | properties(VERTEX).age |
+-------------+-------------------------+------------------------+
| "player149" | "Ben Simmons" | 22 |
| "player134" | "Blake Griffin" | 30 |
| "player149" | "Ben Simmons" | 22 |
+-------------+-------------------------+------------------------+
nebula> LOOKUP ON player \
WHERE player.name == "Kobe Bryant" \
WHERE player.name == "Kobe Bryant"\
YIELD properties(vertex).name AS name |\
GO FROM $-.VertexID OVER serve \
YIELD $-.name, properties(edge).start_year, properties(edge).end_year, properties($$).name;
+---------------+------------------+----------------+--------------+
| $-.name | serve.start_year | serve.end_year | $$.team.name |
+---------------+------------------+----------------+--------------+
| "Kobe Bryant" | 1996 | 2016 | "Lakers" |
+---------------+------------------+----------------+--------------+
+---------------+-----------------------------+---------------------------+---------------------+
| $-.name | properties(EDGE).start_year | properties(EDGE).end_year | properties($$).name |
+---------------+-----------------------------+---------------------------+---------------------+
| "Kobe Bryant" | 1996 | 2016 | "Lakers" |
+---------------+-----------------------------+---------------------------+---------------------+
```

## Retrieve edges
Expand All @@ -144,10 +144,9 @@ nebula> LOOKUP ON follow \
+-------------+-------------+---------+
| SrcVID | DstVID | Ranking |
+-------------+-------------+---------+
| "player101" | "player102" | 0 |
| "player133" | "player114" | 0 |
| "player133" | "player144" | 0 |
+-------------+-------------+---------+
| "player150" | "player143" | 0 |
| "player150" | "player137" | 0 |
| "player148" | "player136" | 0 |
...
nebula> LOOKUP ON follow \
Expand All @@ -156,10 +155,9 @@ nebula> LOOKUP ON follow \
+-------------+-------------+---------+-------------------------+
| SrcVID | DstVID | Ranking | properties(EDGE).degree |
+-------------+-------------+---------+-------------------------+
| "player121" | "player116" | 0 | 90 |
| "player121" | "player128" | 0 | 90 |
| "player121" | "player129" | 0 | 90 |
+-------------+-------------+---------+-------------------------+
| "player150" | "player143" | 0 | 90 |
| "player150" | "player137" | 0 | 90 |
| "player148" | "player136" | 0 | 90 |
...
nebula> LOOKUP ON follow \
Expand Down Expand Up @@ -210,26 +208,26 @@ For example, if there is a `player` tag with a `name` property and an `age` prop
+-------------+
```

- The following example shows how to retrieve the source Vertex IDs, destination vertex IDs, and ranks of all edges of the `like` edge type.
- The following example shows how to retrieve the source Vertex IDs, destination vertex IDs, and ranks of all edges of the `follow` edge type.

```ngql
nebula> CREATE EDGE like(likeness int);
nebula> CREATE EDGE follow(degree int);
nebula> CREATE EDGE INDEX like_index on like();
nebula> CREATE EDGE INDEX follow_index on follow();
nebula> REBUILD EDGE INDEX like_index;
nebula> REBUILD EDGE INDEX follow_index;
+------------+
| New Job Id |
+------------+
| 88 |
+------------+
nebula> INSERT EDGE like(likeness) \
nebula> INSERT EDGE follow(degree) \
VALUES "player100"->"player101":(95);
The following statement retrieves all edges with the edge type `like`. It is similar to `MATCH (s)-[e:like]->(d) RETURN id(s), rank(e), id(d) /*, type(e) */`.
The following statement retrieves all edges with the edge type `follow`. It is similar to `MATCH (s)-[e:follow]->(d) RETURN id(s), rank(e), id(d) /*, type(e) */`.
nebula)> LOOKUP ON like;
nebula)> LOOKUP ON follow;
+-------------+-------------+---------+
| SrcVID | DstVID | Ranking |
+-------------+-------------+---------+
Expand All @@ -239,26 +237,26 @@ For example, if there is a `player` tag with a `name` property and an `age` prop

## Count the numbers of vertices or edges

The following example shows how to count the number of vertices tagged with `player` and edges of the `like` edge type.
The following example shows how to count the number of vertices tagged with `player` and edges of the `follow` edge type.

```ngql
nebula> LOOKUP ON player |\
YIELD COUNT(*) AS Player_Number;
+---------------+
| Player_Number |
+---------------+
| 2 |
| 51 |
+---------------+
nebula> LOOKUP ON like | \
YIELD COUNT(*) AS Like_Number;
+-------------+
| Like_Number |
+-------------+
| 1 |
+-------------+
nebula> LOOKUP ON follow | \
YIELD COUNT(*) AS Follow_Number;
+---------------+
| Follow_Number |
+---------------+
| 81 |
+---------------+
```

!!! note

You can also use [`show-stats`](./6.show/14.show-stats.md) to count the numbers of vertices or edges.
You can also use [`SHOW STATS`](./6.show/14.show-stats.md) to count the numbers of vertices or edges.

0 comments on commit f16a4c4

Please sign in to comment.