Please help create SQL query

Hello!
I’m new to orientDB

The graph contains a tree structure (“is_parent”), the leaves of the graph are linearly ordered (">next>").
It is required to write a query, the node identifier is sent to the input, the output requires either the rightmost leaf - the descendant from the node, or the leftmost leaf is the descendant of the incoming node.

Example - rightsql(18:32)=17:34
leftsql(18:32)=18:33
rightsql(17:32)=18:34
leftsql(17:33)=rightsql(17:33)=18:34

Please help!!!

I’ve been tormented for a week now, I don’t understand how to do this.

If many edges of the same class point to a vertex, a query of the edges results in an array of connected vertices. You must filter the result thus

select from ( traverse inE('is_parent').out from #17:32 while true ) where $depth >= 0  ( add your criteria here, 

or

match {class: V, where: ( @rid = #17:32 )} <-is_parent- { as: a, while: (true) , where : ( your criteria) } return a