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-example-for-getting-vertex/edge-without-specifying-tag/edge-type #1773

Merged
merged 2 commits into from
Nov 23, 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/2.quick-start/6.cheatsheet-for-ngql.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@
| Match vertices | `(v)` | You can use a user-defined variable in a pair of parentheses to represent a vertex in a pattern. For example: `(v)`. |
| Match tags | `MATCH (v:player) RETURN v` | You can specify a tag with `:<tag_name>` after the vertex in a pattern. |
| Match multiple tags | `MATCH (v:player:team) RETURN v LIMIT 10` | To match vertices with multiple tags, use colons (:). |
| 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 vertex properties | `MATCH (v:player{name:"Tim Duncan"}) RETURN v` <br><br>`MATCH (v) WITH v, properties(v) as props, keys(properties(v)) as kk LIMIT 10000 WHERE [i in kk where props[i] == "Tim Duncan"] RETURN v` | You can specify a vertex property with `{<prop_name>: <prop_value>}` after the tag in a pattern; or use a vertex property value to get vertices directly. |
| 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.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`<br>`MATCH ()<-[e]-() RETURN e LIMIT 3` | 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 LIMIT 5` |Just like vertices, you can specify an edge type with `:<edge_type>` in a pattern. For example: `-[e:follow]-`. |
| Match edge type properties | ` MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) RETURN e` | You can specify edge type properties with `{<prop_name>: <prop_value>}` in a pattern. For example: `[e:follow{likeness:95}]`. |
| Match edge type properties | ` MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) RETURN e` <br><br>`MATCH ()-[e]->() WITH e, properties(e) as props, keys(properties(e)) as kk LIMIT 10000 WHERE [i in kk where props[i] == 90] RETURN e`| You can specify edge type properties with `{<prop_name>: <prop_value>}` in a pattern. For example: `[e:follow{likeness:95}]`; or use an edge type property value to get edges directly. |
| Match multiple edge types | `MATCH (v:player{name:"Tim Duncan"})-[e:follow | :serve]->(v2) RETURN e` | The `|` symbol can help matching multiple edge types. For example: `[e:follow|:serve]`. The English colon (:) before the first edge type cannot be omitted, but the English colon before the subsequent edge type can be omitted, such as `[e:follow|serve]`. |
| Match multiple edges | `MATCH (v:player{name:"Tim Duncan"})-[]->(v2)<-[e:serve]-(v3) RETURN v2, v3` | You can extend a pattern to match multiple edges in a path. |
| Match fixed-length paths | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) RETURN DISTINCT v2 AS Friends` | You can use the `:<edge_type>*<hop>` pattern to match a fixed-length path. `hop` must be a non-negative integer. The data type of `e` is the list.|
Expand Down
34 changes: 34 additions & 0 deletions docs-2.0/3.ngql-guide/7.general-query-statements/2.match.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ nebula> MATCH (v:player) \

In openCypher 9, `=` is the equality operator. However, in nGQL, `==` is the equality operator and `=` is the assignment operator (as in C++ or Java).


You also use properties without specifying a tag to get vertices directly. For example, to get all the vertices with the vertex property value Tim Duncan.

```ngql
nebula> MATCH (v) \
WITH v, properties(v) as props, keys(properties(v)) as kk \
LIMIT 10000 WHERE [i in kk where props[i] == "Tim Duncan"] \
RETURN v;
+----------------------------------------------------+
| v |
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+
```

### Match VIDs

You can use the VID to match a vertex. The `id()` function can retrieve the VID of a vertex.
Expand Down Expand Up @@ -399,6 +414,25 @@ nebula> MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) \
+--------------------------------------------------------+
```


You also use properties without specifying an edge type to get edges directly. For example, to get all the edges with the edge property value 90.

```ngql
nebula> MATCH ()-[e]->() \
WITH e, properties(e) as props, keys(properties(e)) as kk \
LIMIT 10000 WHERE [i in kk where props[i] == 90] \
RETURN e;
+----------------------------------------------------+
| e |
+----------------------------------------------------+
| [:follow "player125"->"player100" @0 {degree: 90}] |
| [:follow "player140"->"player114" @0 {degree: 90}] |
| [:follow "player133"->"player144" @0 {degree: 90}] |
| [:follow "player133"->"player114" @0 {degree: 90}] |
...
+----------------------------------------------------+
```

### Match multiple edge types

The `|` symbol can help matching multiple edge types. For example: `[e:follow|:serve]`. The English colon (:) before the first edge type cannot be omitted, but the English colon before the subsequent edge type can be omitted, such as `[e:follow|serve]`.
Expand Down