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

Transform project results into a single list in Gremlin query

我有一个 gremlin 查询,我想 return 一组用户 ID。目前它是 return 一个数组数组。每个投影一个数组。

有没有办法在查询中将这个数组转换为单个用户 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']