在Gremlin查询中将项目结果转换为单个列表



我有一个gremlin查询,我想返回一个用户ID数组。目前它正在返回一个数组数组。每个投影对应一个阵列。

有没有办法将这个数组数组转换为查询中的单个用户id数组,或者这是我需要在应用程序级别处理的问题?

非常感谢您的帮助。

g.V('testUser').fold()
.coalesce(
unfold().project('bi_directional_connection', 'single_directional_connection')
.by(
bothE('bi_directional_connection')
.has('status', 'ACCEPTED')
.otherV()
.has('active', true)
.values('user_id')
.fold()
.dedup()
.limit(100)
)
.by(
outE('single_directional_connection')
.otherV()
.values('user_id')
.fold()
.dedup()
.limit(100)
).select(values),

project('err').by(constant("user does not exist"))
)

编辑:这是我的样本数据

// Set up test data
g.addV('joshTest1')
.property(T.id, 'joshTest1')
.property(single, 'user_id', 'joshTest1')
.property(single, 'role', 'test-user')
.property(single, 'active', true)
.addV('joshTest2')
.property(T.id, 'joshTest2')
.property(single, 'user_id', 'joshTest2')
.property(single, 'role', 'test-user')
.property(single, 'active', true)
.addV('joshTest3')
.property(T.id, 'joshTest3')
.property(single, 'user_id', 'joshTest3')
.property(single, 'role', 'test-user')
.property(single, 'active', true)
.addV('joshTest4')
.property(T.id, 'joshTest4')
.property(single, 'user_id', 'joshTest4')
.property(single, 'role', 'test-user')
.property(single, 'active', true)
.addE('single_directional_connection')
.from(V('joshTest2'))
.to(V('joshTest1'))
.property('status', 'ACCEPTED')
.addE('single_directional_connection')
.from(V('joshTest3'))
.to(V('joshTest1'))
.property('status', 'ACCEPTED')
.addE('bi_directional_connection')
.from(V('joshTest2'))
.to(V('joshTest3'))
.property('status', 'ACCEPTED')
.addE('bi_directional_connection')
.from(V('joshTest3'))
.to(V('joshTest2'))
.property('status', 'ACCEPTED')
.addE('bi_directional_connection')
.from(V('joshTest2'))
.to(V('joshTest4'))
.property('status', 'ACCEPTED')
.addE('bi_directional_connection')
.from(V('joshTest4'))
.to(V('joshTest2'))
.property('status', 'ACCEPTED')

以下是我对示例数据运行查询时得到的响应。我在AWS Jupyter笔记本上做这件事。

[['joshTest3', 'joshTest4', 'joshTest3', 'joshTest4'], ['joshTest1']]

注意,我也得到了我不想要的副本。

我想得到的是:

['joshTest3', 'joshTest4', 'joshTest1']

这里有一个让你开始的答案。我把dedup移到了fold之前,并在最后对结果进行了按摩。我将进一步研究这个查询,如果我提出一个更简单的查询作为选项,我将更新这个答案。

g.V('joshTest2').fold()
.coalesce(
unfold().project('bi_directional_connection', 'single_directional_connection')
.by(
bothE('bi_directional_connection')
.has('status', 'ACCEPTED')
.otherV()
.has('active', true)
.values('user_id')
.dedup()
.fold()
.limit(100)
)
.by(
outE('single_directional_connection')
.otherV()
.values('user_id')
.dedup()
.fold()
.limit(100)
).select(values)
.unfold()
.unfold()
.fold(),

project('err').by(constant("user does not exist"))
)

这产生

['joshTest3', 'joshTest4', 'joshTest1']

最新更新