SQL query rewritter for columnar database