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 #1011

Merged
merged 4 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ There are only two ways to locate `start vid`:

2. For example, `LOOKUP ON player WHERE player.name == "Tony Parker"` or `MATCH (v:player {name:"Tony Parker"})` locates `start vid` by the index of the property `player.name`.

!!! Caution "You cannot perform a global scan without `start vid`"
!!! caution

For example, `match (n) return n;` returns an error because `start vid` cannot be located at this time. As a global scan, it is forbidden.
For example, `match (n) return n;` returns an error: `Scan vertices or edges need to specify a limit number, or limit number can not push down.`, because it is a global scan, you must use the `LIMIT` clause to limit the number of returns.
10 changes: 5 additions & 5 deletions docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
| Match vertex properties | `MATCH (v:player{name:"Tim Duncan"}) RETURN v` | You can specify a vertex property with `{<prop_name>: <prop_value>}` after the tag in a pattern. |
| Match a VID. | `MATCH (v) WHERE id(v) == 'player101' RETURN v` | You can use the VID to match a vertex. The `id()` function can retrieve the VID of a vertex. |
| Match multiple VIDs. | `MATCH (v:player { name: 'Tim Duncan' })--(v2) WHERE id(v2) IN ["player101", "player102"] RETURN v2` | To match multiple VIDs, use `WHERE id(v) IN [vid_list]`. |
| Match connected vertices | `MATCH (v:player{name:"Tim Duncan"})--(v2) RETURN v2.name AS Name` | You can use the `--` symbol to represent edges of both directions and match vertices connected by these edges. You can add a `>` or `<` to the `--` symbol to specify the direction of an edge. |
| Match connected vertices | `MATCH (v:player{name:"Tim Duncan"})--(v2) RETURN v2.player.name AS Name` | You can use the `--` symbol to represent edges of both directions and match vertices connected by these edges. You can add a `>` or `<` to the `--` symbol to specify the direction of an edge. |
| Match paths | `MATCH p=(v:player{name:"Tim Duncan"})-->(v2) RETURN p` | Connected vertices and edges form a path. You can use a user-defined variable to name a path as follows. |
| Match edges | `MATCH (v:player{name:"Tim Duncan"})-[e]-(v2) RETURN e` | Besides using `--`, `-->`, or `<--` to indicate a nameless edge, you can use a user-defined variable in a pair of square brackets to represent a named edge. For example: `-[e]-`. |
| Match an edge type | `MATCH ()-[e:follow]-() RETURN e` |Just like vertices, you can specify an edge type with `:<edge_type>` in a pattern. For example: `-[e:follow]-`. |
Expand All @@ -221,7 +221,7 @@
| Retrieve vertex or edge information | `MATCH (v:player{name:"Tim Duncan"}) RETURN v`<br>`MATCH (v:player{name:"Tim Duncan"})-[e]->(v2) RETURN e` | Use `RETURN {<vertex_name> | <edge_name>}` to retrieve all the information of a vertex or an edge. |
| Retrieve VIDs | `MATCH (v:player{name:"Tim Duncan"}) RETURN id(v)` | Use the `id()` function to retrieve VIDs. |
| Retrieve tags | `MATCH (v:player{name:"Tim Duncan"}) RETURN labels(v)` | Use the `labels()` function to retrieve the list of tags on a vertex.<br>To retrieve the nth element in the `labels(v)` list, use `labels(v)[n-1]`. |
| Retrieve a single property on a vertex or an edge | `MATCH (v:player{name:"Tim Duncan"}) RETURN v.age` | Use `RETURN {<vertex_name> | <edge_name>}.<property>` to retrieve a single property.<br>Use `AS` to specify an alias for a property. |
| Retrieve a single property on a vertex or an edge | `MATCH (v:player{name:"Tim Duncan"}) RETURN v.player.age` | Use `RETURN {<vertex_name> | <edge_name>}.<property>` to retrieve a single property.<br>Use `AS` to specify an alias for a property. |
| Retrieve all properties on a vertex or an edge | `MATCH p=(v:player{name:"Tim Duncan"})-[]->(v2) RETURN properties(v2)` | Use the `properties()` function to retrieve all properties on a vertex or an edge. |
| Retrieve edge types | `MATCH p=(v:player{name:"Tim Duncan"})-[e]->() RETURN DISTINCT type(e)` | Use the `type()` function to retrieve the matched edge types. |
| Retrieve paths | `MATCH p=(v:player{name:"Tim Duncan"})-[*3]->() RETURN p` | Use `RETURN <path_name>` to retrieve all the information of the matched paths. |
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` | Finds all the vertices connected directly to vertex `"player100"`, groups the result set by player names, and counts how many times the name shows up in the result set. |
| [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` | Returns the 3 rows of data starting from the second row of the sorted output. |
| [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` can be used alone to set the offset and return the data after the specified position. |
| [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` can be used alone to set the offset and return the data after the specified position. |
| [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` | The `ORDER BY` clause specifies the order of the rows in the output. |
| [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` | Returns the first three rows with values of the vertex properties `name` and `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` | Returns the first three rows with values of the vertex properties `name` and `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"` | Create a tag and set the TTL options. |
| [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` | The `WHERE` clause filters the output by conditions. The `WHERE` clause usually works in Native nGQL `GO` and `LOOKUP` statements, and OpenCypher `MATCH` and `WITH` statements. |
| [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` | The `WHERE` clause filters the output by conditions. The `WHERE` clause usually works in Native nGQL `GO` and `LOOKUP` statements, and OpenCypher `MATCH` and `WITH` statements. |
| [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` | Finds the players that "player100" follows and calculates their average age. |
| [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` | The `WITH` clause can retrieve the output from a query part, process it, and pass it to the next query part as the input. |

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 @@ -74,6 +74,10 @@ It is a known issue. Just retry 1 to N times, where N is the partition number. T

Starting with Nebula Graph 3.0, the statements `LOOKUP`, `GO`, and `FETCH` must output results with the `YIELD` clause. For more information, see [YIELD](../3.ngql-guide/8.clauses-and-options/yield.md).

### "How to resolve the error `To get the property of the vertex in 'v.age', should use the format 'var.tag.prop'`?"

From version 3.0, `Pattern` supports matching multiple tags at the same time, so you need to specify additional Tag names when returning attributes. From `RETURN variable_name.property_name` change to `RETURN variable_name.Tag.property_name`.

### "How is the `time spent` value at the end of each return message calculated?"

Take the returned message of `SHOW SPACES` as an example:
Expand Down Expand Up @@ -162,9 +166,9 @@ For more information, see [`INDEX`](../3.ngql-guide/14.native-index-statements/1

### "How to get all the vertices/edges without specifying the types?"

By nGQL, you CAN NOT directly getting all the vertices without specifying the tags, neither the edges.
By nGQL, you CAN NOT directly getting all the vertices without specifying the tags, neither the edges, or you can use the `LIMIT` clause to limit the number of returns.

E.g., You CAN NOT run `MATCH (n) RETURN (n)`. An error like `can’t solve the start vids from the sentence` will be returned.
E.g., You CAN NOT run `MATCH (n) RETURN (n)`. An error like `Scan vertices or edges need to specify a limit number, or limit number can not push down.` will be returned.

You can use [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 @@ -134,7 +134,7 @@ Feature: Basic match
When executing query:
"""
MATCH (v1:player{name: "LeBron James"}) -[r]-> (v2)
RETURN type(r) AS Type, v2.name AS Name
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 does not have strict formatting requirements, but creating nGQL statements

```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;
```

Recommended:

```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 @@ In nGQL statements, characters other than keywords, punctuation marks, and blank

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

Recommended:

```ngql
MATCH (v:player{name: "Tim Duncan", age: 42})-[e:follow]-> \
()-[e:serve]->()<--(v3) \
()-[e: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 @@ -108,12 +108,12 @@ The `DURATION` data type is used to indicate a period of time. Map data that are
```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;
+------------+
| v.p1 |
+------------+
| 2021-03-17 |
+------------+
nebula> MATCH (v:date1) RETURN v.date1.p1;
+------------------+
| v.date1.p1.month |
+------------------+
| 3 |
+------------------+
```

4. Create a tag named `school` with the property of `TIMESTAMP`.
Expand Down
14 changes: 6 additions & 8 deletions docs-2.0/3.ngql-guide/5.operators/1.comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,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 |
| false | true | true |
| 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 @@ The `CONTAINS` operator requires string types on both left and right sides.

```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, ...
...

# The following example aggregates all the players' names by their ages.
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 @@ -43,7 +43,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 @@ -52,7 +52,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 \

# b: The statement in the following example retrieves the age distribution of the players in the dataset.
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
Loading