gremlin - Gremlin connected components prints one by one
问题描述
I'm newbie to the gremlin QL, My requirement to generate the connected components on huge graph. I tried the below query but it's printing as a group of values but I need to print one by one.
Connected components Query:
g.V().emit(cyclicPath().or().not(both())).repeat(both()).until(cyclicPath()).path().aggregate("p").unfold().dedup().map(__.as("v").select("p").unfold().filter(unfold().where(eq("v"))).unfold().dedup().order().by(id).fold()).dedup()
[v[89826185]]
[v[89826188], v[89826189], v[89826190], v[89826191], v[89826192], v[89826193], v[89826194]]
[v[89826195], v[89826196], v[89826198]]
I need to print the values like below way. min-id of group(list) to each element of the group(list).
Ex:
89826188 89826189
89826188 89826190
89826188 89826191
89826188 89826192
89826188 89826193
89826188 89826194
89826188 89826188 (self)
解决方案
您可以在应用程序的代码中执行此操作。在查询级别执行此操作只会放大结果大小,但您可以这样做:
g.V().
emit(cyclicPath().or().not(both())).
repeat(both()).
until(cyclicPath()).
path().aggregate("p").
unfold().dedup().
map(__.as("v").select("p").unfold().
filter(unfold().where(eq("v"))).
unfold().dedup().
order().
by(id).
fold()).
dedup().as("list").
unfold().
map(union(select("list").
by(limit(local, 1)),
identity()).
id().fold())
它基本上是相同的查询,我只添加了最后map()
一步来重新格式化结果。
推荐阅读
- module - 了解如何扩展 Julia 模块
- c# - OpenID Connect:如何在认证后检索用户信息和创建原理
- python - 如何记忆/散列 **kwargs(或一般的字典)以用作键
- javascript - 有没有办法设置适用于 Safari 的 cookie?
- django - Django静态图像显示然后不显示,视图共享静态徽标图像所在的基本Html文件
- python - 多处理功能不停止
- javascript - 组织产品类别 Angular
- javascript - 如何通过变量元素的标签名称找到子元素?
- python - -W 如何与 DeprecationWarning 和 PendingDeprecationWarning 交互?
- amazon-web-services - 对于 AWS 区域内的每个可用区