Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example to README to handle PK Chunking with Parallel Concurrency #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,40 @@ Additionally if you want to do something more sophisticated you can provide a he

``bulk.create_query_job(object_name, contentType='CSV', pk_chunking='chunkSize=50000; startRow=00130000000xEftMGH')``

Example:

.. code-block:: python

import unicodecsv
# Create a Job with PK Chunking enabled and with Parallel Concurrency
job_id = bulk.create_query_job(salesforceObject, contentType='CSV', concurrency='Parallel', pk_chunking=True)

# Add one or more batches to the job
bulk.query(job_id, query)

# Wait for each batch to finish
while not bulk.job_status(job_id)['numberBatchesTotal'] == bulk.job_status(job_id)['numberBatchesCompleted']:
print("Not done")
sleep(10)
print("Done")

# Get list of batch Ids
batch_id_list = [batch['id'] for batch in bulk.get_batch_list(job_id) if batch['state'] == 'Completed']

# Retrieve the Results
data = []
for batch_id in batch_id_list:
for result in bulk.get_all_results_for_query_batch(batch_id, job_id, chunk_size=1000000):
reader = unicodecsv.DictReader(result)
for row in reader:
data.append(row)

# Close the job
bulk.close_job(job_id)

print("Done retrieving data")
print(data)

Bulk Insert, Update, Delete
---------------------------

Expand Down