Reconstruct query strings from the ast

This pull request isn't ready to be merged yet. This is just a place
holder.

This pull request modifies the query string generating code to use the
ast instead of doing some regex hacks on the original query
string. This is useful in case where we have to modify the query ast and
generate a query string that will parse to the new ast for serialization
to the nodes in the cluster.