‫Hello and welcome back.
‫In this lecture, we're going to take a look at the sample solution for the sum of number problem.
‫Let's open the sum of numbers Solution file under the sum of number package.
‫We first load the prime number file as a string RTD.
‫Next, we'll need to call flatMap Transformation to split each row into numbers using Whitespaces as
‫the delimiter.
‫We use a reg expression here to match any consecutive number of white spaces.
‫However, the split results might contain empty strings as well.
‫So we need to filter out those empty strings.
‫In this way, we get back a new string with each item being the string representation of one of the
‫first 100 numbers.
‫Then we do a map transformation to convert each number from string type to an integer.
‫Finally, we can call the Reduce action, the integer and the reduce function we pass in takes two arguments.
‫What the function does is to return the sum of those two arguments.
‫This reduced operation will be applied to all the items in RTD and return a single value, which is
‫the sum of all the integers in the input RTD.
‫Let's run this application.
‫See, the sum of the first 100 prime numbers is two four, one three.
‫That's it for this lecture.
‫I hope you have enjoyed it.