From 3f945600625954dbd470ca753a91ce7533e51762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=99=93=E9=9D=92?= <86282370+izhuxiaoqing@users.noreply.github.com> Date: Fri, 15 Oct 2021 16:01:55 +0800 Subject: [PATCH] update lookup --- .../keywords-and-reserved-words.md | 1 + .../7.general-query-statements/5.lookup.md | 69 +++++++++++++------ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/docs-2.0/3.ngql-guide/1.nGQL-overview/keywords-and-reserved-words.md b/docs-2.0/3.ngql-guide/1.nGQL-overview/keywords-and-reserved-words.md index 011c85ba50a..616d73dbb0c 100644 --- a/docs-2.0/3.ngql-guide/1.nGQL-overview/keywords-and-reserved-words.md +++ b/docs-2.0/3.ngql-guide/1.nGQL-overview/keywords-and-reserved-words.md @@ -43,6 +43,7 @@ RETURN DESCRIBE DESC VERTEX +VERTICES EDGE EDGES UPDATE diff --git a/docs-2.0/3.ngql-guide/7.general-query-statements/5.lookup.md b/docs-2.0/3.ngql-guide/7.general-query-statements/5.lookup.md index 1299379211c..6652042e09a 100644 --- a/docs-2.0/3.ngql-guide/7.general-query-statements/5.lookup.md +++ b/docs-2.0/3.ngql-guide/7.general-query-statements/5.lookup.md @@ -1,5 +1,7 @@ # LOOKUP + + The `LOOKUP` statement traverses data based on indexes. You can use `LOOKUP` for the following purposes: - Search for the specific data based on conditions defined by the `WHERE` clause. @@ -35,7 +37,7 @@ Before using the `LOOKUP` statement, make sure that at least one index is create ```ngql LOOKUP ON { | } [WHERE [AND ...]] -[YIELD ]; +[YIELD [AS ]]; [AS ] [, [AS ] ...]; @@ -43,11 +45,12 @@ LOOKUP ON { | } - `WHERE `: filters data with specified conditions. Both `AND` and `OR` are supported between different expressions. For more information, see [WHERE](../8.clauses-and-options/where.md). -- `YIELD `: specifies the results to be returned and the format of the results. +- `YIELD`: Define the output to be returned. + + - When you `LOOKUP` a Tag, the defined properties and `VertexID` are returned. If there is no `YIELD` clause, `VertexID` is returned. + - When you `LOOKUP` an Edge type, the defined properties, `SrcVertexID`, `DstVertexID`, and `rank` are returned. If there is no `YIELD` clause, `SrcVertexID`, `DstVertexID`, and `rank` are returned. -- If there is a `WHERE` clause but no `YIELD` clause: - - The Vertex ID is returned when you `LOOKUP` a tag. - - The source vertex ID, destination vertex ID, and rank of the edge are returned when `LOOKUP` an edge type. +- `AS`: Set an alias. ## Limitations of using `WHERE` in `LOOKUP` @@ -75,31 +78,53 @@ nebula> REBUILD TAG INDEX index_player; nebula> LOOKUP ON player \ WHERE player.name == "Tony Parker"; -============ -| VertexID | -============ -| 101 | ------------- ++-------------+ +| VertexID | ++-------------+ +| "player101" | ++-------------+ nebula> LOOKUP ON player \ WHERE player.name == "Tony Parker" \ + YIELD player.name AS name, player.age AS age; ++-------------+---------------+-----+ +| VertexID | name | age | ++-------------+---------------+-----+ +| "player101" | "Tony Parker" | 36 | ++-------------+---------------+-----+ + +nebula> LOOKUP ON player \ + WHERE player.age > 45; ++-------------+ +| VertexID | ++-------------+ +| "player144" | ++-------------+ +| "player140" | ++-------------+ + +nebula> LOOKUP ON player \ + WHERE player.name STARTS WITH "B" \ + AND player.age IN [22,30] \ YIELD player.name, player.age; -======================================= -| VertexID | player.name | player.age | -======================================= -| 101 | Tony Parker | 36 | ---------------------------------------- ++-------------+-----------------+------------+ +| VertexID | player.name | player.age | ++-------------+-----------------+------------+ +| "player149" | "Ben Simmons" | 22 | ++-------------+-----------------+------------+ +| "player134" | "Blake Griffin" | 30 | ++-------------+-----------------+------------+ nebula> LOOKUP ON player \ WHERE player.name == "Kobe Bryant" \ YIELD player.name AS name |\ GO FROM $-.VertexID OVER serve \ YIELD $-.name, serve.start_year, serve.end_year, $$.team.name; -================================================================== -| $-.name | serve.start_year | serve.end_year | $$.team.name | -================================================================== -| Kobe Bryant | 1996 | 2016 | Lakers | ------------------------------------------------------------------- ++---------------+------------------+----------------+--------------+ +| $-.name | serve.start_year | serve.end_year | $$.team.name | ++---------------+------------------+----------------+--------------+ +| "Kobe Bryant" | 1996 | 2016 | "Lakers" | ++---------------+------------------+----------------+--------------+ ``` ## Retrieve Edges @@ -186,7 +211,7 @@ For example, if there is a `player` tag with a `name` property and an `age` prop nebula> LOOKUP ON player; +-------------+ - | _vid | + | VertexID | +-------------+ | "player100" | +-------------+ @@ -215,7 +240,7 @@ For example, if there is a `player` tag with a `name` property and an `age` prop nebula)> LOOKUP ON like; +-------------+----------+-------------+ - | _src | _ranking | _dst | + | VertexID | DstVID | _dst | +-------------+----------+-------------+ | "player100" | 0 | "player101" | +-------------+----------+-------------+