复杂的match语句怎成go

match path=(n:Company{code:’’})-[r:IndustryCompanyRelationship]-(b:Industry)-[g:IndustryRelationship | IndustryMinceRelationship* 5]->()-[o:IndustryCompanyRelationship]-(m:Company{code:’’})
with node(path) as w,o.start_valid_date as o.start_valid_date,
o.failure_date as o.failure_date,r.start_valid_date as r.start_valid_date as r.start_valid_date,r.failure_date as r.failure_date,path as path where date(o.start_valid_date)<date()
and date(o.failure_date) > date() and date(r.failure_date) > date()
unwind w as w1 return size(collect(distincet w1)) as testLength as testLength

go 语句和 match 语句的 路径模型是不一样的,所以像这样的长 pattern 理论上并不能完全等价的转化成 go 语句写法。

1 个赞

您好,提这样写法的问题,转换成 basketball player 的query,会比较好一些,别人都有这个数据集,比较容易帮助你。

获得 nodes(path) ngql 没法写,除非有的情况下用 FIND PATH 过滤边的条件,得不偿失。

你的语句好像写错了

MATCH path=(n:Company{code:’’})-[r:IndustryCompanyRelationship]-(b:Industry)-[g:IndustryRelationship | IndustryMinceRelationship* 5]->()-[o:IndustryCompanyRelationship]-(m:Company{code:’’})
WITH 
  node(path) AS w,o.start_valid_date AS o.start_valid_date,
  o.failure_date AS o.failure_date,r.start_valid_date AS xxx,
  r.start_valid_date AS r.start_valid_date,
  r.failure_date AS r.failure_date,path AS path
WHERE 
  date(o.start_valid_date)<date()
  AND 
  date(o.failure_date) > date() 
  AND 
  date(r.failure_date) > date()
UNWIND w AS w1 
RETURN 
  size(collect(distinct w1)) AS testLength
1 个赞

哪里有问题啊?

怎么转 basketball player啊?

您好,可以尽量把等价的 query 尽量用这个数据集的对应的查询去写哈,不过确实有时候这个数据集不能完全覆盖您的需求。

https://docs.nebula-graph.com.cn/2.6.1/3.ngql-guide/1.nGQL-overview/1.overview/#basketballplayer

drop space basketballplayer;
create space basketballplayer(partition_num=10,replica_factor=1,vid_type=fixed_string(32));
:sleep 20
use basketballplayer;
create tag player(name string,age int);
create tag team(name string);
create edge serve(start_year int,end_year int);
create edge follow(degree int);
:sleep 20
create tag index player_index_0 on player();
create tag index player_index_1 on player(name(20));
:sleep 20
insert vertex player(name,age) values “player100”:(“Tim Duncan”, 42);

basketballplayer文件是这个,这个怎么解决我的问题啊?

抱歉,我没说清楚,我的意思是提问 query 的问题建议把您本来的query表达成 basketballplayer 对应的数据里的 query,像是之前回答您问题的时候我会写类似这样的 query,他的好处是任何一个人可以在自己的环境快速帮助你、重现你的需求哈。

MATCH path=(n:player{name: "Tim Duncan"})--(g) \
WITH nodes(path) AS w, path AS path UNWIND w AS w1 \
RETURN path, size(collect(DISTINCT w1)) AS testLength, length(path) + 1 as pathLength | \
YIELD $-.path as path, $-.testLength as testLength \
WHERE $-.testLength == $-.pathLength

这会大大降低回复您问题的同学的门槛

为什么要是 basketballplayer,不都一样的吗

哈,是我太菜了,:sob:,我觉得用大家共的数据集去做一些尝试会方便一些。
否则提供schema/测试数据

哪你能用go写出来吗?用match性能不好

你的这句怎么转成go啊?

这样的 path 的表达在 go 里做不到,关于性能

可以新开一个帖子,把 profile 的输出分享一下,大家一起看看慢在哪里

是查不出数据IndustryMinceRelationship*4,改成1-5,查5次直接报错

match path=(n:Company{code:'142417250861'})-[r:IndustryCompanyRelationship]-(b:Industry)  \
-[g:IndustryRelationship | IndustryMinceRelationship*4]-(m:Industry{code:'49030105'}) WITH   \
 nodes(path) as w,r.start_valid_date as start_valid_date,r.failure_date as failure_date,path as path   \ where date(start_valid_date)<date() and date(failure_date) > date() UNWIND w as w1 return   \ size(collect(distinct w1)) as testLength,path,length(path)+1 as pathLength,length(path) as le | yield  \ $-.path as p,$-.le as le,$-.testLength as testLength,$-.pathLength as pathLength where  \ $-.testLength==$-.pathLength ) | order by $-.le asc | OFFSET 1 LIMIT 10 

1-5 您是怎么写的? 这么写是OK的 1..5,可以贴一下报错么哈?

(root@nebula) [basketballplayer]> 
MATCH p=(v:player{name:"Tim Duncan"})-[e:serve|follow*1..3]->(v2)  \
    RETURN DISTINCT v2 AS last_step, count(v2);
+-----------------------------------------------------------+-----------+
| last_step                                                 | count(v2) |
+-----------------------------------------------------------+-----------+
| ("team203" :team{name: "Trail Blazers"})                  | 1         |
| ("player101" :player{age: 36, name: "Tony Parker"})       | 3         |
| ("player102" :player{age: 33, name: "LaMarcus Aldridge"}) | 1         |
| ("player125" :player{age: 41, name: "Manu Ginobili"})     | 3         |
| ("team204" :team{name: "Spurs"})                          | 7         |
| ("team215" :team{name: "Hornets"})                        | 1         |
| ("player100" :player{age: 42, name: "Tim Duncan"})        | 4         |
+-----------------------------------------------------------+-----------+

是这个条查询语句,查询5次,每次改变的只是旁边的数字比如*1,*2,数据量时,查询一个他们没有路径的结果,会报错

可以帮忙贴一下具体报错么?
可能和 return 的方式有关系,我写的简单的情况还没能触发报错,我也试着把你的 RETURN 形式写进来看能不能重现。

(root@nebula) [basketballplayer]> 

MATCH p=(v:player{name:"Tim Duncan"})-[e:serve|follow*8]->(v2) \
         RETURN DISTINCT v2 AS last_step, count(v2);
+-----------+-----------+
| last_step | count(v2) |
+-----------+-----------+
+-----------+-----------+
Empty set (time spent 21035/23957 us)

Tue, 16 Nov 2021 06:17:06 UTC

java.lang.RuntimeException:N5folly13BrokenPromiseE: Broken promise for type name ‘nebula::Status’

这是 java client 的异常,nebula console 上有么?

浙ICP备20010487号