Divide queries into maps and reductions