我的问题是"如何对match
结果进行分组" select
- ed项目?
以下是我的图表中的结构和数据:
结构:
user
/ experience
/ school
/ company
/ tag
studied
/ worked
/ school
/ company
/ speaks
数据:
我已经使用match
,dedup
和unfold
g.V(16520).match(
__.as('user'),
__.as('user').out('worked').as('workExperiences'),
__.as('user').out('studied').as('schoolExperiences'),
__.as('workExperiences').out('company').as('company'),
__.as('schoolExperiences').out('school').as('school'),
__.as('user').outE('speaks').as('a').values('level').as('level').select('a').inV().values('name').as('language').select('level', 'language').as('languages')
).select('user', 'schoolExperiences', 'school', 'workExperiences', 'company', 'languages')
.unfold().dedup()
以下是此查询提供的内容:
==>user=v[16520]
==>schoolExperiences=v[4184]
==>school=v[4232]
==>workExperiences=v[12496]
==>company=v[8320]
==>languages={level=6, language=DEU}
==>languages={level=3, language=FRA}
==>schoolExperiences=v[16424]
==>school=v[4136]
==>workExperiences=v[16512]
==>company=v[4176]
我需要找到一个返回这种结果的查询:
==>user=[v[16520]]
==>languages=[{level=6, language=DEU},{level=3, language=FRA}]
==>workExperiences=[v[12496], v[16512]]
==>schoolExperiences=[v[4184], v[16424]]
==>company=[v[4176], v[8320]]
==>school=[v[4136], v[4232]]
我无法找到解决方案。
任何建议都会受到关注:)
感谢您阅读
F。
PS:我正在运行v3.0.1孵化的Tinkerpop版本
答案 0 :(得分:1)
感谢@DanielKuppitz这里是我需要的解决方案:
g.V(16520).as('user').match(
__.as('user').out('worked').as('experience').out('company').as('companyId').select('experience', 'companyId').fold().as('tmpWorkExperiences'),
__.as('user').out('studied').as('experience').out('school').as('schoolId').select('experience', 'schoolId').fold().as('tmpSchoolExperiences'),
__.as('user').outE('speaks').as('level').inV().as('language').select('level', 'language').by('level').by('name').fold().as('languages')
).select('tmpWorkExperiences').map(unfold().select('experience', 'companyId').by().by(id).fold()).as('workExperiences').
select('tmpWorkExperiences').map(unfold().select('companyId').fold()).as('company').
select('tmpSchoolExperiences').map(unfold().select('experience', 'schoolId').by().by(id).fold()).as('schoolExperiences').
select('tmpSchoolExperiences').map(unfold().select('schoolId').fold()).as('school').
select('workExperiences', 'schoolExperiences', 'company', 'school', 'languages').unfold()
结果如下:
==>workExperiences=[{experience=v[12496], companyId=8320}, {experience=v[16512], companyId=4176}]
==>schoolExperiences=[{experience=v[4184], schoolId=4232}, {experience=v[16424], schoolId=4136}]
==>company=[v[8320], v[4176]]
==>school=[v[4232], v[4136]]
==>languages=[{level=6, language=DEU}, {level=3, language=FRA}]