Follow these steps until the issue is resolved
  1. Make the query static instead of dynamic
  2. Break the large query into smaller groups and do the export twice