This seems like an awful lot of logic for query parsing! Wonder if this shouldn't happen somewhere in the schedulers...