Here what we found. The query has a subquery. If you uncheck the option 'Remove subqueries' then it'll work. For some reason, when that option is set, the query is getting reformatted incorrectly, which is causing the error.
We created a bug ID for this: Bug ID TOR-2632
PS. If you turn off the refactoring option, then it will work. Maybe an option for you.