Hi i am working on the following graph graph model of the current scenario
i am traversing from school vertex to subject,games and hobbies vertex
so i wrote a below query which is giving me all the student details
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()
output:
[
{
"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"
]
}
]
}
]
As in the above output "student_name" is repeating and wanted to group by on "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')
but above Query is throwing error as follows
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.
Please let me know how to achieve the above requirement or any other alternative to achieve the above requirement one can be "i can group by on the student vertex and then move forward with projection later"
in that case my output can be as follows
[
{
"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"
]
}
]
}
]
NOTE: output may not be the exact but the crux is grouping by on the projected values or grouping by and processing the traversal for the each grouped by vertex after group by or any other alternative to achieve it.
please let me know the possibility of the query for the same or any other alternative for this
You should use select
step
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'))
example: https://gremlify.com/vfnvlkfvybc