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

Match edges <--> (for two edges in bi-direction) #3665

Open
lvphpwb opened this issue Jan 7, 2022 · 4 comments
Open

Match edges <--> (for two edges in bi-direction) #3665

lvphpwb opened this issue Jan 7, 2022 · 4 comments
Labels
community Source: who proposed the issue type/enhancement Type: make the code neat or more efficient

Comments

@lvphpwb
Copy link

lvphpwb commented Jan 7, 2022

目前有--、-->、<--

是否可以加上<-->

@lvphpwb lvphpwb added the type/enhancement Type: make the code neat or more efficient label Jan 7, 2022
@Sophie-Xie Sophie-Xie changed the title 匹配边查询 Match edges <--> Jan 7, 2022
@wey-gu
Copy link
Contributor

wey-gu commented Jan 7, 2022

Thanks @lvphpwb , it seems <--> is already valid and equivalent to -- :)

(root@nebula) [basketballplayer]> match (n:player)<-[]->(m:player) where id(n)=="player100" return m
+-----------------------------------------------------------+
| m                                                         |
+-----------------------------------------------------------+
| ("player101" :player{age: 36, name: "Tony Parker"})       |
| ("player102" :player{age: 33, name: "LaMarcus Aldridge"}) |
| ("player104" :player{age: 32, name: "Marco Belinelli"})   |
| ("player105" :player{age: 31, name: "Danny Green"})       |
| ("player107" :player{age: 32, name: "Aron Baynes"})       |
| ("player108" :player{age: 36, name: "Boris Diaw"})        |
| ("player109" :player{age: 34, name: "Tiago Splitter"})    |
| ("player113" :player{age: 29, name: "Dejounte Murray"})   |
| ("player125" :player{age: 41, name: "Manu Ginobili"})     |
| ("player144" :player{age: 47, name: "Shaquille O'Neal"})  |
| ("player101" :player{age: 36, name: "Tony Parker"})       |
| ("player125" :player{age: 41, name: "Manu Ginobili"})     |
+-----------------------------------------------------------+
Got 12 rows (time spent 8153/9552 us)

Fri, 07 Jan 2022 12:58:50 UTC

(root@nebula) [basketballplayer]> match (n:player)<-->(m:player) where id(n)=="player100" return m
+-----------------------------------------------------------+
| m                                                         |
+-----------------------------------------------------------+
| ("player101" :player{age: 36, name: "Tony Parker"})       |
| ("player102" :player{age: 33, name: "LaMarcus Aldridge"}) |
| ("player104" :player{age: 32, name: "Marco Belinelli"})   |
| ("player105" :player{age: 31, name: "Danny Green"})       |
| ("player107" :player{age: 32, name: "Aron Baynes"})       |
| ("player108" :player{age: 36, name: "Boris Diaw"})        |
| ("player109" :player{age: 34, name: "Tiago Splitter"})    |
| ("player113" :player{age: 29, name: "Dejounte Murray"})   |
| ("player125" :player{age: 41, name: "Manu Ginobili"})     |
| ("player144" :player{age: 47, name: "Shaquille O'Neal"})  |
| ("player101" :player{age: 36, name: "Tony Parker"})       |
| ("player125" :player{age: 41, name: "Manu Ginobili"})     |
+-----------------------------------------------------------+
Got 12 rows (time spent 6734/8136 us)

Fri, 07 Jan 2022 12:59:31 UTC

@lvphpwb
Copy link
Author

lvphpwb commented Jan 8, 2022

-- 是表示出或者入,有一个关联就行
我说的意思是出并且入,双向关系存在

@wey-gu wey-gu changed the title Match edges <--> Match edges <--> (for two edges in bi-direction) Jan 10, 2022
@wey-gu
Copy link
Contributor

wey-gu commented Jan 10, 2022

-- 是表示出或者入,有一个关联就行 我说的意思是出并且入,双向关系存在

Now I understand your question: you meant to use <--> to represent two edges in bi-direction, while this is against the cypher semantic on relationship/edge: <--> and -- means one edge with arbitrary direction rather than two edges.

While to fullfil your requiremnts, multiple match patterns could be used(implemented by #3519 ) in 3.x or master(already merged).

cpyher 里 <-->-- 语义就是等价的,你的表达可以用多 path 的 match 表达,这个 PR(#3519 )引入了它,现在的master和3.0 会支持。

比如

match (a)-->(b), (a)<--(b) where xxx return yyy

@czpmango
Copy link
Contributor

czpmango commented Jan 13, 2022

@lvphpwb Good Question! There are some root causes you can refer to:
A theoretical fact is that the design of pattern has only OR semantics, but no AND semantics.
So it can be described by MATCH's filter or multiple patterns, as follows:

Query1: MATCH (v)-->(n) WHERE exists((n)-->(v)) return v,n
Query2: MATCH (v)-->(n), (n)-->(v) return v,n

Note: Due to cypher's definition of pattern matching and path mode, the semantics of Query1 and Query2 will be different.

Besides, cypher's pattern can only describe directed graphs, so it restricts other combinations of descriptor elements in pattern, such as <-[]->. Based on this, you can treat <-[]-> and -[]- as equivalent, just as @wey-gu said above.


In fact, <-[]-> also has practical implications in mixed graphs.This edge pattern will exclude undirected edge matches, just as <-[]->+~[]~=-[]-(more detail you could refer to the GQL standard, which will be released soon).

@Sophie-Xie Sophie-Xie added the community Source: who proposed the issue label Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Source: who proposed the issue type/enhancement Type: make the code neat or more efficient
Projects
None yet
Development

No branches or pull requests

4 participants