通过不处理 cosmos DB gremlin API 上的预测值来分组

group by not working on the projected values on cosmos DB gremlin API

您好,我正在处理下图 graph model of the current scenario

我正在从学校顶点遍历到学科、游戏和爱好顶点

所以我写了一个下面的查询,它给了我所有学生的详细信息

g.V().hasLabel("school").as('school').out().hasLabel('class').out().hasLabel('student')
.project('student_name','student_details').by('name').by(project('student_description',"reads","plays","havehobbies")
.by('description')
.by(__.outE('reads').inV().values('subject_name').limit(5).dedup().fold())
.by(__.outE("plays").inV().values('game_name').limit(5).dedup().fold())
.by(__.outE('have_hobby').inV().values('hobby_name').dedup().limit(5).fold()).dedup().fold()).dedup()

输出:

[
{
            "student_name": "santhosh kurnapally",
            "student_details": [
                {
                    "student_description": "very good student with high IQ",
                    "reads": [
                        "maths",
                        "science",
                        "social"
                    ],
                    "plays": [
                        "cricket",
                        "football"
                    ],
                    "havehobbies": [
                        "news paper",
                        "tv watching",
                        "cycling"
                    ]
                }
            ]
        },
        {
            "student_name": "santhosh kurnapally",
            "student_details": [
               {
                    "student_description": "very bad student with low IQ",
                    "reads": [
                        "maths",
                        "science"
                    ],
                    "plays": [
                        "cricket",
                        "football"
                    ],
                    "havehobbies": [
                        "news paper",
                        "tv watching"
                    ]
                }
            ]
        },
        {
            "student_name": "neerja goswami",
            "student_details": [
               {
                    "student_description": "very good student with very high IQ",
                    "reads": [
                        "maths",
                        "science",
            "english"
                    ],
                    "plays": [
                        "throw ball",
                        "carroms"
                    ],
                    "havehobbies": [
                        "news paper",
                        "quilling"
                    ]
                }
            ]
        }
]

正如上面的输出“student_name”是重复的,并希望在“student_name”

上分组

g.V().hasLabel("school").as('school').out().hasLabel('class').out().hasLabel('student')
.project('student_name','student_details').by('name').by(project('student_description',"reads","plays","havehobbies")
.by('description')
.by(__.outE('reads').inV().values('subject_name').limit(5).dedup().fold())
.by(__.outE("plays").inV().values('game_name').limit(5).dedup().fold())
.by(__.outE('have_hobby').inV().values('hobby_name').dedup().limit(5).fold()).dedup().fold()).dedup()
.group().by('student_name')

但上面的查询抛出如下错误


ActivityId : 6fa77108-39e3-4f77-ba09-2a2e6ca80d9a
ExceptionType : GraphCompileException
ExceptionMessage :
        Gremlin Query Compilation Error: Column reference R_17["student_name"] cannot be located in the raw records in the current execution pipeline.

请告诉我如何实现上述要求 或实现上述要求的任何其他替代方案 一个可以是“我可以在学生顶点上分组,然后通过投影向前移动”

在那种情况下我的输出可以如下

[
{
            "santhosh kurnapally": [
                {
                    "student_description": ["very good student with high IQ","very bad student with low IQ"]
                    "reads": [
                        "maths",
                        "science",
                        "social"
                    ],
                    "plays": [
                        "cricket",
                        "football"
                    ],
                    "havehobbies": [
                        "news paper",
                        "tv watching",
                        "cycling"
                    ]
                }
            ]
        },
        {
            "neerja goswami": [
               {
                    "student_description": ["very good student with very high IQ"],
                    "reads": [
                        "maths",
                        "science",
            "english"
                    ],
                    "plays": [
                        "throw ball",
                        "carroms"
                    ],
                    "havehobbies": [
                        "news paper",
                        "quilling"
                    ]
                }
            ]
        }
]

注意:输出可能不准确,但关键是对投影值进行分组或分组并处理每个按顶点分组的遍历或任何其他替代方法来实现它。

请让我知道查询相同或任何其他替代方案的可能性

您应该使用 select 步骤

g.V().hasLabel('School').as('school').
  out().hasLabel('Class').out().
  hasLabel('Student').
  project('student_name', 'student_details').
    by('name').
    by(project('student_description', 'reads', 'plays', 'havehobbies').
        by('description').
        by(__.outE('reads').inV().
          values('subject_name').limit(5).dedup().
          fold()).
        by(__.outE('plays').inV().values('game_name').
          limit(5).dedup().fold()).
        by(__.outE('have_hobby').inV().values('hobby_name').
          dedup().limit(5).fold()).
      dedup().fold()).
  dedup().
  group().
    by(select('student_name'))

示例:https://gremlify.com/vfnvlkfvybc