User`s guide
Analyze Large Data Sets in a Database with MapReduce
6-87
% intermKey is 'PartialCountSumDelay'
count = 0;
sum = 0;
while hasnext(intermValIter)
countSum = getnext(intermValIter);
count = count + countSum(1);
sum = sum + countSum(2);
end
meanDelay = sum/count;
% The key-value pair added to outKVStore will become the output of mapreduce
add(outKVStore,'MeanArrivalDelay',meanDelay);
Run MapReduce Using the Mapper and Reducer Functions
Run MapReduce with the DatabaseDatastore object dbds, mapper function
meanArrivalDelayMapper, and reducer function meanArrivalDelayReducer to
calculate the mean arrival delay in the flight data.
outds = mapreduce(dbds,@meanArrivalDelayMapper,@meanArrivalDelayReducer);
Display the Output from MapReduce
Read the table outtab from the output datastore outds using readall.
outtab = readall(outds)
outtab =
Key Value
______ ________
'MeanArrivalDelay' [7.12]
The table has only one row containing one key-value pair.
Display the mean arrival delay meanArrDelay from the table outtab.
meanArrDelay = outtab.Value{1}
meanArrDelay =
7.12
Close the DatabaseDatastore
Close the DatabaseDatastore, cursor, and database connection.