@@ -0,0 +1,954 @@
+ # You can either read text into your Spark from local fileSystem:%0A     mySample_text_RDD = sc.textFile(%22file///directory_to_your_sample_text%22)%0A # or you can read from HDFS(dont forget to put your sample text into hdfs!)%0A     mySample_text_RDD = sc.textFile(%22/directory_of_your_sample_text_in_HDFS/%22)%0A %0A #you can see your first n line by the following command%0A     mySample_text_RDD.take(n)%0A %0A # now mapper is as below:%0A     def split_words(line):%0A         return line.split()%0A      %0A     def create_pair(word):%0A         return (word, 1)%0A         %0A     pairs_RDD = mySample_text_RDD.flatMap(split_words).map(create_pair)%0A     %0A # You can see your output by the following .collect() command%0A %0A     pairs_RDD.collect()%0A     %0A # Now Reducer is in action:%0A %0A     def sum_counts(a,b):%0A         return a+b%0A         %0A      wordCounts_RDD = pairs_RDD.reduceByKey(sum_counts) %0A      %0A # Now lets se what we get as a result%0A %0A     wordCounts_RDD.collect()%0A     %0A %0A

Create Run_Spark_for_WordCount.py