New contribution for review: 'UNTIL' clause for traverse command

25 views
Skip to first unread message

nagaraja sosale ramaswamy

unread,
Jul 24, 2015, 8:43:09 AM7/24/15
to orient-...@googlegroups.com
Hi everyone,

I've introduced a new keyword 'UNTIL' clause in the traverse command that executes the traversal until the condition becomes true (opposite of while clause). 
the implementation is quite trivial, i've added a boolean flag 'negating' to OSQLFilter which if set, causes the result of the evaluation to be negated. 
other changes are in the parser to introduce the new keyword and minor refactoring into OWhileClause and OUntilClause instead of reusing OWhereClause.
i'd appreciate any feedback on this contribution. thanks.

Rationale: suppose i have a graph with a chain of vertices connected by the same edge, where number of vertices in the chain is variable. e.g., User -> Friend(Edge) -> User -> Friend(Edge) -> User -> Friend(Edge) -> User -> Friend(Edge) -> User -> Friend(Edge) -> User 

i want to traverse Friend edges from the starting User node until i reach a particular user satisfying some condition (say Name="James Bond").

Using while clause like this: traverse out('Friend') from <rid> while Name='James Bond' does not work as the traversal condition is false at the first node itself. 
Here the intention is to continue traversing till a condition is satisfied and then stop. 

note: currently this CANNOT be solved by prefixing the condition in while clause with 'NOT' keyword. hence introduction of UNTIL clause. 
note: the evaluation of the negative condition can be optimized to ensure that operators can do 'short circuit', but that is not trivial. as i mentioned my attempt is a naive implementation that perhaps someone can benefit from.

if the code is acceptable then i'll create pull request.

you can view the diff over here:


----------------

the changes are:

core/src/main/grammar/OrientSQL.jjt
line 114, 618: introduce UNTIL keyword and 
line 825-833 and 2113-2128: refactor usage of OWhereClause into OWhileClause and OUntilClause

core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLTraverse.java
line 113-122: handle the new UNTIL keyword

core/src/main/java/com/orientechnologies/orient/core/sql/filter/OSQLFilter.java 
line 121-130: introduce 'negating' flag
line 34-39:  new constructor to set the negating flag
line 106-107: apply the negating flag when returning

core/src/main/java/com/orientechnologies/orient/core/sql/parser/OTraverseStatement.java
line 61-63 and 100-101: handle the until clause

new files:
core/src/main/java/com/orientechnologies/orient/core/sql/parser/OUntilClause.java
core/src/main/java/com/orientechnologies/orient/core/sql/parser/OWhileClause.java

generated file, differences can be ignored:
core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSql.java
core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlConstants.java
core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTokenManager.java
core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTreeConstants.java



Reply all
Reply to author
Forward
0 new messages