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 annotation to some examples of LOOKUP clause #2388

Merged
merged 2 commits into from
Dec 6, 2023
Merged
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
25 changes: 23 additions & 2 deletions docs-2.0-zh/3.ngql-guide/7.general-query-statements/5.lookup.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ YIELD [DISTINCT] <return_list> [AS <alias>]
返回 Tag 为`player`且`name`为`Tony Parker`的点。

```ngql
# 创建 Tag 为 player 的复合属性索引 index_player。
nebula> CREATE TAG INDEX IF NOT EXISTS index_player ON player(name(30), age);

# 重建复合属性索引 index_player,返回任务 id。
nebula> REBUILD TAG INDEX index_player;
+------------+
| New Job Id |
+------------+
| 15 |
+------------+

# 返回所有 name 等于 Tony Parker 的点数据的 ID。
nebula> LOOKUP ON player \
WHERE player.name == "Tony Parker" \
YIELD id(vertex);
Expand All @@ -87,6 +90,7 @@ nebula> LOOKUP ON player \
| "player101" |
+---------------+

# 查询所有 name 等于 Tony Parker 的点数据,返回 name 和 age 属性值。
nebula> LOOKUP ON player \
WHERE player.name == "Tony Parker" \
YIELD properties(vertex).name AS name, properties(vertex).age AS age;
Expand All @@ -96,6 +100,7 @@ nebula> LOOKUP ON player \
| "Tony Parker" | 36 |
+---------------+-----+

# 查询所有 age 大于 45 的点数据,并返回点数据的 ID。
nebula> LOOKUP ON player \
WHERE player.age > 45 \
YIELD id(vertex);
Expand All @@ -106,6 +111,7 @@ nebula> LOOKUP ON player \
| "player140" |
+-------------+

# 查询所有 name 以 B 开头,且 age 在 22 和 30 之间的点数据,并返回 name 和 age 属性值。
nebula> LOOKUP ON player \
WHERE player.name STARTS WITH "B" \
AND player.age IN [22,30] \
Expand All @@ -117,6 +123,7 @@ nebula> LOOKUP ON player \
| "Blake Griffin" | 30 |
+-------------------------+------------------------+

# 查询所有 name 等于 Kobe Bryant 的点数据,返回点的 ID 和 name 属性值,并以此为起始点进行遍历,返回遍历结果。
nebula> LOOKUP ON player \
WHERE player.name == "Kobe Bryant"\
YIELD id(vertex) AS VertexID, properties(vertex).name AS name |\
Expand All @@ -135,15 +142,18 @@ nebula> LOOKUP ON player \
返回 Edge type 为`follow`且`degree`为`90`的边。

```ngql
# 创建 Edge type 为 follow,属性 degree 的索引 index_follow。
nebula> CREATE EDGE INDEX IF NOT EXISTS index_follow ON follow(degree);

# 重建属性索引 index_follow,返回任务 id。
nebula> REBUILD EDGE INDEX index_follow;
+------------+
| New Job Id |
+------------+
| 62 |
+------------+

# 查询并返回所有 degree 等于 90 的边。
nebula> LOOKUP ON follow \
WHERE follow.degree == 90 YIELD edge AS e;
+----------------------------------------------------+
Expand All @@ -154,6 +164,7 @@ nebula> LOOKUP ON follow \
| [:follow "player118"->"player131" @0 {degree: 90}] |
...

# 查询所有 degree 等于 90 的边,并返回 degree 属性值。
nebula> LOOKUP ON follow \
WHERE follow.degree == 90 \
YIELD properties(edge).degree;
Expand All @@ -164,6 +175,7 @@ nebula> LOOKUP ON follow \
| 90 |
...

# 根据 degree 属性值升序排列,并返回前 10 条 degree 属性值。
nebula> LOOKUP ON follow \
YIELD properties(edge).degree as degree \
| ORDER BY $-.degree \
Expand All @@ -183,6 +195,7 @@ nebula> LOOKUP ON follow \
| 70 |
+--------+

# 查询所有 degree 等于 60 的边,返回边的目的点 ID 和边的 degree 属性值,并为此起始点进行遍历,返回遍历结果。
nebula> LOOKUP ON follow \
WHERE follow.degree == 60 \
YIELD dst(edge) AS DstVID, properties(edge).degree AS Degree |\
Expand All @@ -206,22 +219,25 @@ nebula> LOOKUP ON follow \
- 查找所有 Tag 为`player`的点 VID。

```ngql
# 创建名为 player 的 Tag。
nebula> CREATE TAG IF NOT EXISTS player(name string,age int);

# 创建 Tag 为 player 的索引 player_index。
nebula> CREATE TAG INDEX IF NOT EXISTS player_index on player();

# 重建索引 player_index,返回任务 id。
nebula> REBUILD TAG INDEX player_index;
+------------+
| New Job Id |
+------------+
| 66 |
+------------+

# 插入两个点数据。
nebula> INSERT VERTEX player(name,age) \
VALUES "player100":("Tim Duncan", 42), "player101":("Tony Parker", 36);

# 列出所有的 player。类似于 MATCH (n:player) RETURN id(n) /*, n */。

nebula> LOOKUP ON player YIELD id(vertex);
+-------------+
| id(VERTEX) |
Expand All @@ -245,22 +261,25 @@ nebula> LOOKUP ON follow \
- 查找 Edge type 为`follow`的所有边的信息。

```ngql
# 创建名为 follow 的 Edge type。
nebula> CREATE EDGE IF NOT EXISTS follow(degree int);

# 创建 Edge type 为 follow 的索引 follow_index。
nebula> CREATE EDGE INDEX IF NOT EXISTS follow_index on follow();

# 重建索引 follow_index。
nebula> REBUILD EDGE INDEX follow_index;
+------------+
| New Job Id |
+------------+
| 88 |
+------------+

# 插入边数据。
nebula> INSERT EDGE follow(degree) \
VALUES "player100"->"player101":(95);

# 列出所有的 follow 边。类似于 MATCH (s)-[e:follow]->(d) RETURN id(s), rank(e), id(d) /*, type(e) */。

nebula)> LOOKUP ON follow YIELD edge AS e;
+-----------------------------------------------------+
| e |
Expand All @@ -276,6 +295,7 @@ nebula> LOOKUP ON follow \
统计 Tag 为`player`的点和 Edge type 为`follow`的边。

```ngql
# 统计 Tag 为 player 的点总数。
nebula> LOOKUP ON player YIELD id(vertex)|\
YIELD COUNT(*) AS Player_Number;
+---------------+
Expand All @@ -284,6 +304,7 @@ nebula> LOOKUP ON player YIELD id(vertex)|\
| 51 |
+---------------+

# 统计 Edge type 为 follow 的边总数。
nebula> LOOKUP ON follow YIELD edge AS e| \
YIELD COUNT(*) AS Follow_Number;
+---------------+
Expand Down