Behaviour of Coalesce Step

28 views
Skip to first unread message

Udit Sharma

unread,
May 11, 2018, 4:06:18 AM5/11/18
to Gremlin-users
Sample Graph
g=TinkerGraph.open().traversal()
g.addV().property('type','student').property('id','student1').as('s1').
addV().property('type','course').property('id','course1').as('c1').
addV().property('type','teacher').property('id','teacher1').as('t1').
addV().property('type','teacher').property('id','teacher2').as('t2').
addV().property('type','department').property('id','department1').as('d1').
addE('worksFor').from('t1').to('d1').
addE('worksFor').from('t2').to('d1').
addE('headOf').from('t1').to('d1').
addE('teacherOf').from('t1').to('c1').
addE('takesCourse').from('s1').to('c1').
addE('advisor').from('s1').to('t1')

Query 1:
g.V().match(__.as('temp').has('id',"department1"),
__.as('temp').in('worksFor','headOf').as('X')).match(
__.as('X').out('teacherOf').as('Z'),
__.as('Z').in('takesCourse').as('Y'),
__.as('Y').out('advisor').as('X'))

Output:
==>[X:v[6],Y:v[0],Z:v[3]]
==>[X:v[6],Y:v[0],Z:v[3]]

Query 2:
g.V().match(__.as('temp').has('id',"department1"),
__.as('temp').in('worksFor','headOf').as('X')).coalesce(match(
__.as('X').out('teacherOf').as('Z'),
__.as('Z').in('takesCourse').as('Y'),
__.as('Y').out('advisor').as('X')))

Output
==>[X:v[6],Y:v[0],Z:v[3]]
==>[X:v[6],Y:v[0],Z:v[3]]
==>[X:v[6],Y:v[0],Z:v[3]]
==>[X:v[6],Y:v[0],Z:v[3]]

Why output printed by Query 2 is different from the output generated by Query 1? Shouldn't coalesce step behave as it is not present if we pass only a single argument to it?
Reply all
Reply to author
Forward
0 new messages