Gremlin query to check the cycle nature of the graph

49 views Asked by At

I am new to gremlin. I have task where I need to check the cycle nature of the vertex in the graph and return the output in either of the format String or Boolean:

{'crn': 'COMPANY_X', 'cycle': 'Y'}
{'crn': 'COMPANY_X', 'cycle': 'N'}
 or 
{'crn': 'COMPANY_X', 'cycle': true}
{'crn': 'COMPANY_X', 'cycle': false}

I have written a query with my little knowledge, which is throwing MalformedQueryException. There could be multiple errors. I am trying for the String output as mentioned above.

g.
  V('COMPANY_X').as('crn')
  .map(
    repeat(
    outE('HAS_VOTING_PC_TO')
    .by(constant('N')).as('cycle')
    .inV()
    .simplePath())
    .until(not(outE()))
    .where(out().as('crn'))
    .by(constant('Y')).as('cycle')
  .select('crn', 'cycle')
  .project('crn', 'cycle')
    .by(id)
    .by(select(keys).select('cycle'))
  .fold()
  .V('COMPANY_X').as('crn')
  .map(
    repeat(
    outE('HAS_SHRHLDING_PC_TO')
    .by(constant('N')).as('cycle')
    .inV()
    .simplePath())
    .until(not(outE()))
    .where(out().as('crn'))
    .by(constant('Y')).as('cycle')
  .select('crn', 'cycle')
  .project('crn', 'cycle')
    .by(id)
  .by(select(keys).select('cycle'))
  .fold()
  .aggregate('x')
  .unfold()

Can you please guide me where I am going wrong?

I am trying to look for 2 types of edges i.e. HAS_VOTING_PC_TO or HAS_SHRHLDING_PC_TO. If I find the same vertex. I change the value of cycle field to Y. At the beginning it is set as N

Any leads would be really helpful to me. Thank you.

0

There are 0 answers