sqlparsing.find with backwards search doesn't match end of token list

Details

Detail name Value
Changelog Number 8071
Type Bug
Status Resolved
Affected Versions EXASOL 6.0.0, Exasol 6.1.0, Exasol 6.2.0, Exasol 7.0.0-alpha1
Fix Versions Exasol 7.0.0, Exasol 6.2.6
Resolution Date 2020-04-09

Description

The function sqlparsing.find (usually used in the context of preprocessor scripts) does not find a match that is at the end of the token list when searching backwards from the end.
Instead it finds the first match before the end.

Expected Behavior
The last token should be found.

Example

The following script demonstrates the problem. Instead of the matching the last token ('dual' at position 7) the token before ('from' at position 5) is found.

--/
create or replace lua script checkFindBackwardsAtEnd()
as
 tokens = sqlparsing.tokenize("select * from dual")
 results = sqlparsing.find(tokens, #tokens, false, true, sqlparsing.iswhitespaceorcomment, sqlparsing.isany)
 
 exa.output(table.concat(results, ','))
/

--> shows position 5 (from) instead of 7 (dual)
execute script checkFindBackwardsAtEnd() with output;