This is a similar question to this, but that didn't specifically ask about accessing the data in a later step.
You could start here with these two steps, (as mentioned in the other answer):
Passing data from each partition to the top-level job
1) Use the exit status of each partition to represent the number of records read for that partition.
2) Use the PartitionAnalyzer.analyzeStatus
to aggregate these into a single object on the top-level thread.
E.g., supposing each partition's exit status was set to a stringified Integer representing the number of records processed by that partition, you could aggregate them like this (shown here using a briefly-outlined, custom PartitionData class):
// Assumes persistent user data initialized somewhere else
public void analyzeStatus(BatchStatus batchStatus,
String exitStatus) throws Exception {
if (batchStatus.equals(BatchStatus.COMPLETED)) {
PartitionData ud = (PartitionData)stepCtx.getPersistentUserData();
int numRecords = Integer.parseInt(exitStatus);
pd.incrementCount(numRecords);
} // else maybe do something else
// ...
}
// Your own class
public class PartitionData {
int totalNumRecords;
public incrementCount(int numRecords) {
totalNumRecords += numRecords;
}
}
//
// Setting partition exit status as num records processed not shown !
//
This is thread-safe as the spec guarantees analyzeStatus will be called separately, on a single thread, as each partition ends.
Passing data from one step to the next (in a persistent manner)
Now, at this point you might think to simply set this aggregate object into the job's transient user data. The problem here is that if the job fails on the next step, and you restart it at that next step, this data would not then be populated (in the job transient user data), on restart.
So it would be best to persist this aggregate object somehow. It is possible to leverage the batch container's persistent store (the "job repository") by using the first (partitioned) step's persistent user data. This isn't a one-liner though, so I won't show it unless you ask.