Star

match与多Tag的兼容性

请教一下,在match语句里可以访问同一个vertex的不同tag的属性吗?我看文档里貌似是不可以的。

类似下面这样吗?

(root@nebula) [nba]> desc tag player
+--------+----------+-------+---------+
| Field  | Type     | Null  | Default |
+--------+----------+-------+---------+
| "name" | "string" | "YES" |         |
+--------+----------+-------+---------+
| "age"  | "int64"  | "YES" |         |
+--------+----------+-------+---------+
Got 2 rows (time spent 1317/1732 us)

Wed, 20 Jan 2021 17:01:18 CST

(root@nebula) [nba]> desc tag bachelor
+--------------+----------+-------+---------+
| Field        | Type     | Null  | Default |
+--------------+----------+-------+---------+
| "name"       | "string" | "YES" |         |
+--------------+----------+-------+---------+
| "speciality" | "string" | "YES" |         |
+--------------+----------+-------+---------+
Got 2 rows (time spent 1533/1984 us)

Wed, 20 Jan 2021 17:01:23 CST

(root@nebula) [nba]> match (v:player{name: "Tim Duncan"}) RETURN v.age, v.speciality, labels(v) as labels
+-------+--------------+------------------------+
| v.age | v.speciality | labels                 |
+-------+--------------+------------------------+
| 42    | "psychology" | ["bachelor", "player"] |
+-------+--------------+------------------------+
Got 1 rows (time spent 6767/7186 us)

Wed, 20 Jan 2021 17:01:26 CST

player和bachelor两个tag都有name属性,return v.name的时候我试了好像只会返回其中一个tag的name属性,而通过GO语句是可以指定哪个tag的name属性的

这里是为了跟 openCyher 保持兼容,才做成这样的。其实客户端是把所有的 tag 的属性都返回了,如果你要在客户端使用,可以直接拿点,然后自己去拿哪个 tag 的哪个属性都是可以的:

(root@nebula) [nba]> match (v:player{name: "Tim Duncan"}) RETURN v
+-------------------------------------------------------------------------------------------------------------+
| v                                                                                                           |
+-------------------------------------------------------------------------------------------------------------+
| ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) |
+-------------------------------------------------------------------------------------------------------------+
Got 1 rows (time spent 7388/7821 us)

Wed, 20 Jan 2021 17:15:05 CST
1赞

在where条件里有办法基于player的name进行过滤吗?

就这个 case 而言,已经使用了 player.name 进行的过滤,为什么还要在 WHERE 中再加过滤呢?能否写一下你的使用用例?

是这样,我是希望通过vid的方式选定起始点,假设通过follow关系跳转到v2,v2也是具有player和bachelor两个tag,这时我想通过player的name属性对v2进行过滤,这个有办法实现吗?

如果像示例中的 player 和 bachelor 一样,有相同的 tag 属性,match 中是不好区分哪个 tag 的。这个如果又是必须的话,可以使用 GO 来实现。

预格式化文本将缩进 4 格
match (v)-[:follow]->(v2) where id(v) == 'player102' and v2.name== 'Tony Parker' return v2;
[ERROR (-8)]: Can't solve the start vids from the sentence: MATCH (v)-[:follow]->(v2) WHERE ((id(v)==player102) AND (v2.name==Tony Parker)) RETURN v2

还有个问题麻烦也看下,按照我刚才说的case,报这个错,但是我对v2的条件应该跟起始vid无关吧?

你好,这里是 MATCH 的实现的问题,现在索引提取还有一些工作正在做,目前的 case 可以通过如下的方式来规避一下:

(root@nebula) [nba]> match p=(v)-[:like]-(v2 {name: "Tony Parker"}) where id(v) == "Tim Duncan" return v2, p
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| v2                                                    | p                                                                                                                                                                                             |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})<-[:like@0 {likeness: 95}]-("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Got 2 rows (time spent 8845/9414 us)

Thu, 21 Jan 2021 10:01:20 CST
1赞

浙ICP备20010487号