Skip to content

Commit

Permalink
Loop through CSV results for large data sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
WWJacob committed Apr 5, 2012
1 parent 6a9527a commit 8f9e68c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/salesforce_bulk/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,19 @@ def get_batch_result()

if(@@operation == "query") # The query op requires us to do another request to get the results
response_parsed = XmlSimple.xml_in(response)
result_id = response_parsed["result"][0]

path = "job/#{@@job_id}/batch/#{@@batch_id}/result/#{result_id}"
headers = Hash.new
headers = Hash["Content-Type" => "text/xml; charset=UTF-8"]
#puts "path is: #{path}\n"

response = @@connection.get_request(nil, path, headers)
#puts "\n\nres2: #{response.inspect}\n\n"

# Large data sets get split into multiple CSV files.
results_array = []
response_parsed["result"].each do |result_id|
path = "job/#{@@job_id}/batch/#{@@batch_id}/result/#{result_id}"
headers = Hash.new
headers = Hash["Content-Type" => "text/xml; charset=UTF-8"]

results_array += @@connection.get_request(nil, path, headers).lines.to_a
end
end

response = response.lines.to_a.join
csvRows = CSV.parse(response)[1..-1]
CSV.parse(results_array.join)[1..-1]
end

end
Expand Down

1 comment on commit 8f9e68c

@javierjulio
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wwjacob thanks! This is the proof I've been looking for. I wasn't sure if the API does return multiple query result sets for a single batch. The way the response is structured I thought it would be so I supported that feature but I couldn't replicate it. Look into my salesforcebulk gem I've just released as it processes each result set individually whereas here in this update you are building one massive array. It handles this case where a single query batch can have multiple result sets defined.

Please sign in to comment.