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

update match statement #1361

Merged
merged 6 commits into from
Jan 7, 2022
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
4 changes: 2 additions & 2 deletions docs-2.0/1.introduction/3.vid.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ VID 的数据类型必须在[创建图空间](../3.ngql-guide/9.space-statements

2. 例如 `LOOKUP ON player WHERE player.name == "Tony Parker"` 或者 `MATCH (v:player {name:"Tony Parker"}) `,是通过属性 `player.name` 的索引来定位到 `start vid`;

!!! caution "不能在没有 `start vid` 情况下进行全局扫描"
!!! caution

例如 `match (n) return n;` 会返回错误,因为此时无法定位到 `start vid`;这是一个全局扫描,因此被禁止
`match (n) return n;` 会返回错误`Scan vertices or edges need to specify a limit number, or limit number can not push down.`,这是一个全局扫描,需要用`LIMIT`子句限制返回数量才能执行
10 changes: 5 additions & 5 deletions docs-2.0/2.quick-start/6.cheatsheet-for-ngql-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
| 匹配点的属性 | `MATCH (v:player{name:"Tim Duncan"}) RETURN v` | 用户可以在 Tag 的右侧用`{<prop_name>: <prop_value>}`表示模式中点的属性。 |
| 匹配单点 ID | `MATCH (v) WHERE id(v) == 'player101' RETURN v` | 用户可以使用点 ID 去匹配点。`id()`函数可以检索点的 ID。 |
| 匹配多点 ID | `MATCH (v:player { name: 'Tim Duncan' })--(v2) WHERE id(v2) IN ["player101", "player102"] RETURN v2` | 要匹配多个点的 ID,可以用`WHERE id(v) IN [vid_list]`。 |
| 匹配连接的点 | `MATCH (v:player{name:"Tim Duncan"})--(v2) RETURN v2.name AS Name` | 用户可以使用`--`符号表示两个方向的边,并匹配这些边连接的点。用户可以在`--`符号上增加`<`或`>`符号指定边的方向。 |
| 匹配连接的点 | `MATCH (v:player{name:"Tim Duncan"})--(v2) RETURN v2.player.name AS Name` | 用户可以使用`--`符号表示两个方向的边,并匹配这些边连接的点。用户可以在`--`符号上增加`<`或`>`符号指定边的方向。 |
| 匹配路径 | `MATCH p=(v:player{name:"Tim Duncan"})-->(v2) RETURN p` | 连接起来的点和边构成了路径。用户可以使用自定义变量命名路径。 |
| 匹配边 | `MATCH (v:player{name:"Tim Duncan"})-[e]-(v2) RETURN e` | 除了用`--`、`-->`、`<--`表示未命名的边之外,用户还可以在方括号中使用自定义变量命名边。例如`-[e]-`。 |
| 匹配 Edge type | `MATCH ()-[e:follow]-() RETURN e` | 和点一样,用户可以用`:<edge_type>`表示模式中的 Edge type,例如`-[e:follow]-`。 |
Expand All @@ -221,7 +221,7 @@
| 检索点或边的信息 | `MATCH (v:player{name:"Tim Duncan"}) RETURN v`<br>`MATCH (v:player{name:"Tim Duncan"})-[e]->(v2) RETURN e` | 使用`RETURN {<vertex_name> | <edge_name>}`检索点或边的所有信息。 |
| 检索点 ID | `MATCH (v:player{name:"Tim Duncan"}) RETURN id(v)` | 使用`id()`函数检索点 ID。 |
| 检索 Tag | `MATCH (v:player{name:"Tim Duncan"}) RETURN labels(v)` | 使用`labels()`函数检索点上的 Tag 列表。<br>检索列表`labels(v)`中的第 N 个元素,可以使用`labels(v)[n-1]`。 |
| 检索点或边的单个属性 | `MATCH (v:player{name:"Tim Duncan"}) RETURN v.age` | 使用`RETURN {<vertex_name> | <edge_name>}.<property>`检索单个属性。<br>使用`AS`设置属性的别名。 |
| 检索点或边的单个属性 | `MATCH (v:player{name:"Tim Duncan"}) RETURN v.player.age` | 使用`RETURN {<vertex_name> | <edge_name>}.<property>`检索单个属性。<br>使用`AS`设置属性的别名。 |
| 检索点或边的所有属性 | `MATCH p=(v:player{name:"Tim Duncan"})-[]->(v2) RETURN properties(v2)` | 使用`properties()`函数检索点或边的所有属性。 |
| 检索 Edge type | `MATCH p=(v:player{name:"Tim Duncan"})-[e]->() RETURN DISTINCT type(e)` | 使用`type()`函数检索匹配的 Edge type。 |
| 检索路径 | `MATCH p=(v:player{name:"Tim Duncan"})-[*3]->() RETURN p` | 使用`RETURN <path_name>`检索匹配路径的所有信息。 |
Expand Down Expand Up @@ -340,11 +340,11 @@
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| [GROUP BY](../3.ngql-guide/8.clauses-and-options/group-by.md) | ` GROUP BY <var> YIELD <var>, <aggregation_function(var)>` | `GO FROM "player100" OVER follow BIDIRECT YIELD $$.player.name as Name | GROUP BY $-.Name YIELD $-.Name as Player, count(*) AS Name_Count` | 查找所有连接到 player100 的点,并根据他们的姓名进行分组,返回姓名的出现次数。 |
| [LIMIT](../3.ngql-guide/8.clauses-and-options/limit.md) | `YIELD <var> [| LIMIT [<offset_value>,] <number_rows>]` | `O FROM "player100" OVER follow REVERSELY YIELD $$.player.name AS Friend, $$.player.age AS Age | ORDER BY $-.Age, $-.Friend | LIMIT 1, 3` | 从排序结果中返回第 2 行开始的 3 行数据。 |
| [SKIP](../3.ngql-guide/8.clauses-and-options/limit.md) | `RETURN <var> [SKIP <offset>] [LIMIT <number_rows>]` | `MATCH (v:player{name:"Tim Duncan"}) --> (v2) RETURN v2.name AS Name, v2.age AS Age ORDER BY Age DESC SKIP 1` | 用户可以单独使用`SKIP <offset>`设置偏移量,后面不需要添加`LIMIT <number_rows>`。 |
| [SKIP](../3.ngql-guide/8.clauses-and-options/limit.md) | `RETURN <var> [SKIP <offset>] [LIMIT <number_rows>]` | `MATCH (v:player{name:"Tim Duncan"}) --> (v2) RETURN v2.player.name AS Name, v2.player.age AS Age ORDER BY Age DESC SKIP 1` | 用户可以单独使用`SKIP <offset>`设置偏移量,后面不需要添加`LIMIT <number_rows>`。 |
| [ORDER BY](../3.ngql-guide/8.clauses-and-options/order-by.md) | `<YIELD clause> ORDER BY <expression> [ASC | DESC] [, <expression> [ASC | DESC] ...]` | `FETCH PROP ON player "player100", "player101", "player102", "player103" YIELD player.age AS age, player.name AS name | ORDER BY $-.age ASC, $-.name DESC` | `ORDER BY`子句指定输出结果的排序规则。 |
| [RETURN](../3.ngql-guide/8.clauses-and-options/return.md) | `RETURN {<vertex_name>|<edge_name>|<vertex_name>.<property>|<edge_name>.<property>|...}` | `MATCH (v:player) RETURN v.name, v.age LIMIT 3` | 返回点的属性为`name`和`age`的前三行值。 |
| [RETURN](../3.ngql-guide/8.clauses-and-options/return.md) | `RETURN {<vertex_name>|<edge_name>|<vertex_name>.<property>|<edge_name>.<property>|...}` | `MATCH (v:player) RETURN v.player.name, v.player.age LIMIT 3` | 返回点的属性为`name`和`age`的前三行值。 |
| [TTL](../3.ngql-guide/8.clauses-and-options/ttl-options.md) | ``CREATE TAG <tag_name>(<property_name_1> <property_value_1>, <property_name_2> <property_value_2>, ...) ttl_duration= <value_int>, ttl_col = <property_name>`` | `CREATE TAG t2(a int, b int, c string) ttl_duration= 100, ttl_col = "a"` | 创建 Tag 并设置 TTL 选项。 |
| [WHERE](../3.ngql-guide/8.clauses-and-options/where.md) | `WHERE {<vertex|edge_alias>.<property_name> {>|==|<|...} <value>...}` | `MATCH (v:player) WHERE v.name == "Tim Duncan" XOR (v.age < 30 AND v.name == "Yao Ming") OR NOT (v.name == "Yao Ming" OR v.name == "Tim Duncan") RETURN v.name, v.age` | `WHERE`子句可以根据条件过滤输出结果,通常用于`GO`和`LOOKUP`语句,`MATCH`和`WITH`语句。 |
| [WHERE](../3.ngql-guide/8.clauses-and-options/where.md) | `WHERE {<vertex|edge_alias>.<property_name> {>|==|<|...} <value>...}` | `MATCH (v:player) WHERE v.player.name == "Tim Duncan" XOR (v.player.age < 30 AND v.player.name == "Yao Ming") OR NOT (v.player.name == "Yao Ming" OR v.player.name == "Tim Duncan") RETURN v.player.name, v.player.age` | `WHERE`子句可以根据条件过滤输出结果,通常用于`GO`和`LOOKUP`语句,`MATCH`和`WITH`语句。 |
| [YIELD](../3.ngql-guide/8.clauses-and-options/yield.md) | `YIELD [DISTINCT] <col> [AS <alias>] [, <col> [AS <alias>] ...] [WHERE <conditions>];` | `GO FROM "player100" OVER follow YIELD dst(edge) AS ID | FETCH PROP ON player $-.ID YIELD player.age AS Age | YIELD AVG($-.Age) as Avg_age, count(*)as Num_friends` | 查找 player100 关注的 player,并计算他们的平均年龄。 |
| [WITH](../3.ngql-guide/8.clauses-and-options/with.md) | `MATCH $expressions WITH {nodes()|labels()|...}` | `MATCH p=(v:player{name:"Tim Duncan"})--() WITH nodes(p) AS n UNWIND n AS n1 RETURN DISTINCT n1` | `WITH`子句可以获取并处理查询前半部分的结果,并将处理结果作为输入传递给查询的后半部分。 |

Expand Down
8 changes: 6 additions & 2 deletions docs-2.0/20.appendix/0.FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Nebula Graph {{ nebula.release }} 的数据模型中,异常情况下可能会

从 Nebula Graph 3.0 开始,查询语句`LOOKUP`、`GO`、`FETCH`必须用`YIELD`子句指定输出结果。详情请参见[YIELD](../3.ngql-guide/8.clauses-and-options/yield.md)。

### 如何处理错误信息 `To get the property of the vertex in 'v.age', should use the format 'var.tag.prop'`

从 3.0 版本开始,`pattern`支持同时匹配多个 Tag,所以返回属性时,需要额外指定 Tag 名称。即从`RETURN 变量名.属性名`改为`RETURN 变量名.Tag.属性名`。

### 返回消息中 `time spent` 的含义是什么?

将命令`SHOW SPACES`返回的消息作为示例:
Expand Down Expand Up @@ -165,9 +169,9 @@ Storage 服务使用 Raft 协议(多数表决),为保证可用性,要求

nGQL 没有该功能。

你必须先指定 Tag/EdgeType,才能获取对应类型的所有的点和边。
你必须先指定 Tag/EdgeType,或者用`LIMIT`子句限制返回数量,才能获取对应类型的所有的点和边。

例如执行 `MATCH (n) RETURN (n)`. 会返回错误 `can’t solve the start vids from the sentence`。
例如执行 `MATCH (n) RETURN (n)`. 会返回错误 `Scan vertices or edges need to specify a limit number, or limit number can not push down.`。

一个办法是使用 [Nebula Algorithm](../nebula-algorithm.md).

Expand Down
2 changes: 1 addition & 1 deletion docs-2.0/3.ngql-guide/1.nGQL-overview/1.overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Feature: Basic match
When executing query:
"""
MATCH (v1:player{name: "LeBron James"}) -[r]-> (v2)
RETURN type(r) AS Type, v2.name AS Name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这个文档中加个兼容性提示,然后FAQ里面也说明下。

RETURN type(r) AS Type, v2.player.name AS Name
"""
Then the result should be, in any order:

Expand Down
10 changes: 5 additions & 5 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 @@ -50,16 +50,16 @@ nGQL 没有严格的构建格式要求,但根据恰当而统一的风格创建

```ngql
MATCH (v:player{name:"Tim Duncan"})-[e]->(v2) \
WHERE (v2.name STARTS WITH "Y" AND v2.age > 35 AND v2.age < v.age) OR (v2.name STARTS WITH "T" AND v2.age < 45 AND v2.age > v.age) \
WHERE (v2.player.name STARTS WITH "Y" AND v2.player.age > 35 AND v2.player.age < v.player.age) OR (v2.player.name STARTS WITH "T" AND v2.player.age < 45 AND v2.player.age > v.player.age) \
RETURN v2;
```

推荐:

```ngql
MATCH (v:player{name:"Tim Duncan"})-[e]->(v2) \
WHERE (v2.name STARTS WITH "Y" AND v2.age > 35 AND v2.age < v.age) \
OR (v2.name STARTS WITH "T" AND v2.age < 45 AND v2.age > v.age) \
WHERE (v2.player.name STARTS WITH "Y" AND v2.player.age > 35 AND v2.player.age < v.player.age) \
OR (v2.player.name STARTS WITH "T" AND v2.player.age < 45 AND v2.player.age > v.player.age) \
RETURN v2;
```

Expand Down Expand Up @@ -125,15 +125,15 @@ nGQL 没有严格的构建格式要求,但根据恰当而统一的风格创建

```ngql
MATCH (v:player{name: "Tim Duncan", age: 42}) \
-[e:follow]->()-[e:serve]->()<--(v3) \
-[e:follow]->()-[e2:serve]->()<--(v2) \
RETURN v, e, v2;
```

推荐:

```ngql
MATCH (v:player{name: "Tim Duncan", age: 42})-[e:follow]-> \
()-[e:serve]->()<--(v3) \
()-[e2:serve]->()<--(v2) \
RETURN v, e, v2;
```

Expand Down
12 changes: 6 additions & 6 deletions docs-2.0/3.ngql-guide/3.data-types/4.date-and-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@
```ngql
nebula> CREATE TAG INDEX IF NOT EXISTS date1_index ON date1(p1);
nebula> REBUILD TAG INDEX date1_index;
nebula> MATCH (v:date1) RETURN v.p1.month;
+------------+
| v.p1.month |
+------------+
| 3 |
+------------+
nebula> MATCH (v:date1) RETURN v.date1.p1.month;
+------------------+
| v.date1.p1.month |
+------------------+
| 3 |
+------------------+
```

4. 创建 Tag,名称为`school`,包含`TIMESTAMP`类型。
Expand Down
12 changes: 6 additions & 6 deletions docs-2.0/3.ngql-guide/5.operators/1.comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ nebula> WITH {name: 'Mats', name2: 'Pontus'} AS map1, \
+-------------------+-----------------------+-------------------+

nebula> MATCH (n:player) \
RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NULL;
+---------------+--------------------+-----------------+
| n.age IS NULL | n.name IS NOT NULL | n.empty IS NULL |
+---------------+--------------------+-----------------+
| false | true | true |
+---------------+--------------------+-----------------+
RETURN n.player.age IS NULL, n.player.name IS NOT NULL, n.player.empty IS NULL;
+----------------------+---------------------------+------------------------+
| n.player.age IS NULL | n.player.name IS NOT NULL | n.player.empty IS NULL |
+----------------------+---------------------------+------------------------+
| false | true | true |
| false | true | true |
...
```

Expand Down
16 changes: 8 additions & 8 deletions docs-2.0/3.ngql-guide/5.operators/7.string.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ nebula> UNWIND 'a' AS a UNWIND 'b' AS b RETURN a + b;

```ngql
nebula> MATCH (s:player)-[e:serve]->(t:team) WHERE id(s) == "player101" \
AND t.name CONTAINS "ets" RETURN s.name, e.start_year, e.end_year, t.name;
+---------------+--------------+------------+-----------+
| s.name | e.start_year | e.end_year | t.name |
+---------------+--------------+------------+-----------+
| "Tony Parker" | 2018 | 2019 | "Hornets" |
+---------------+--------------+------------+-----------+
AND t.team.name CONTAINS "ets" RETURN s.player.name, e.start_year, e.end_year, t.team.name;
+---------------+--------------+------------+-------------+
| s.player.name | e.start_year | e.end_year | t.team.name |
+---------------+--------------+------------+-------------+
| "Tony Parker" | 2018 | 2019 | "Hornets" |
+---------------+--------------+------------+-------------+

nebula> GO FROM "player101" OVER serve WHERE (STRING)properties(edge).start_year CONTAINS "19" AND \
properties($^).name CONTAINS "ny" \
Expand Down Expand Up @@ -121,9 +121,9 @@ nebula> RETURN "384748.39" =~ "\\d+(\\.\\d{2})?";
| true |
+--------------------------------+

nebula> MATCH (v:player) WHERE v.name =~ 'Tony.*' RETURN v.name;
nebula> MATCH (v:player) WHERE v.player.name =~ 'Tony.*' RETURN v.player.name;
+---------------+
| v.name |
| v.player.name |
+---------------+
| "Tony Parker" |
+---------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ nebula> WITH [1, 1, 2, 2] AS coll \
+--------+

nebula> MATCH (n:player) \
RETURN collect(n.age);
RETURN collect(n.player.age);
+---------------------------------------------------------------+
| collect(n.age) |
| collect(n.player.age) |
+---------------------------------------------------------------+
| [32, 32, 34, 29, 41, 40, 33, 25, 40, 37, ...
...

# 基于年龄聚合姓名。
nebula> MATCH (n:player) \
RETURN n.age AS age, collect(n.name);
RETURN n.player.age AS age, collect(n.player.name);
+-----+--------------------------------------------------------------------------+
| age | collect(n.name) |
| age | collect(n.player.name) |
+-----+--------------------------------------------------------------------------+
| 24 | ["Giannis Antetokounmpo"] |
| 20 | ["Luka Doncic"] |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ nebula> YIELD \
```

```ngql
nebula> MATCH (v:player) WHERE v.age > 30 \
RETURN v.name AS Name, \
nebula> MATCH (v:player) WHERE v.player.age > 30 \
RETURN v.player.name AS Name, \
CASE \
WHEN v.name STARTS WITH "T" THEN "Yes" \
WHEN v.player.name STARTS WITH "T" THEN "Yes" \
ELSE "No" \
END \
AS Starts_with_T;
Expand Down
4 changes: 2 additions & 2 deletions docs-2.0/3.ngql-guide/6.functions-and-expressions/6.list.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nebula> MATCH (a:player)-[r]->() \
+------------+----------------------------+

nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) \
WHERE a.name == "Tim Duncan" AND c.name == "Spurs" \
WHERE a.player.name == "Tim Duncan" AND c.team.name == "Spurs" \
RETURN nodes(p);
+-----------------------------------------------------------------------------------------------------------------------------------------------+
| nodes(p) |
Expand All @@ -51,7 +51,7 @@ nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) \
| [("player100" :player{age: 42, name: "Tim Duncan"}), ("player125" :player{age: 41, name: "Manu Ginobili"}), ("team204" :team{name: "Spurs"})] |
+-----------------------------------------------------------------------------------------------------------------------------------------------+

nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) WHERE a.name == "Tim Duncan" AND c.name == "Spurs" RETURN relationships(p);
nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) WHERE a.player.name == "Tim Duncan" AND c.team.name == "Spurs" RETURN relationships(p);
+-----------------------------------------------------------------------------------------------------------------------------+
| relationships(p) |
+-----------------------------------------------------------------------------------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ nebula> LOOKUP ON player \

# 方法二:统计数据库中的年龄分布情况。
nebula> MATCH (n:player) \
RETURN n.age as age, count(*) as number \
RETURN n.player.age as age, count(*) as number \
ORDER BY number DESC, age DESC;
+-----+--------+
| age | number |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ nebula> MATCH p = (n:player{name:"LeBron James"})-[:follow]->(m) \
+------+

nebula> MATCH (n:player) \
RETURN exists(n.id), n IS NOT NULL;
RETURN exists(n.player.id), n IS NOT NULL;
+--------------+---------------+
| exists(n.id) | n IS NOT NULL |
+--------------+---------------+
| false | true |
+--------------+---------------+
...

nebula> MATCH (n:player) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MATCH <pattern> [<clause_1>] RETURN <output> [<clause_2>];

!!! compatibility "历史版本兼容性"

从3.0版本开始,`pattern`支持同时匹配多个 Tag,所以返回属性时,需要额外指定 Tag 名称。即从`RETURN 变量名.属性名`改为`RETURN 变量名.Tag.属性名`。
从 3.0 版本开始,`pattern`支持同时匹配多个 Tag,所以返回属性时,需要额外指定 Tag 名称。即从`RETURN 变量名.属性名`改为`RETURN 变量名.Tag.属性名`。

- `clause_2`:支持`ORDER BY`、`LIMIT`子句。

Expand Down
2 changes: 1 addition & 1 deletion 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 @@ -160,7 +160,7 @@ nebula> GO FROM "player100" OVER follow REVERSELY \
# 该 MATCH 查询与上一个 GO 查询具有相同的语义。
nebula> MATCH (v)<-[e:follow]- (v2)-[e2:serve]->(v3) \
WHERE id(v) == 'player100' \
RETURN v2.name AS FriendOf, v3.name AS Team;
RETURN v2.player.name AS FriendOf, v3.team.name AS Team;
+---------------------+-----------------+
| FriendOf | Team |
+---------------------+-----------------+
Expand Down
Loading