use spark sql to rewrite