June 2017
Beginner to intermediate
296 pages
7h 4m
English
Syntactically, there's nothing really special about key/value RDDs, it's all kind of magic in Python. If you are storing a list of two items as your values in the RDD, then it is a key/value RDD and you can treat it as such. Here's a simple example:
totalsByAge = rdd.mapValues(lambda x: (x, 1))
If I want to create a totalsByAge RDD out of an original RDD that contains a single value in each element, my lambda function here, x, can take each rating or each number, whatever happens to be x, and transform that into a pair of the original number and then the number 1. So the syntax with the parentheses indicates that this is a single entity as far as Python is concerned, but it consists of two elements; it's a list ...
Read now
Unlock full access