Complete the code to create a Spark RDD from a text file.
rdd = sparkContext.[1]("data.txt")
The textFile method is used to create an RDD from a text file in Spark.
Complete the code to perform a map operation on an RDD to square each number.
squared_rdd = numbers_rdd.[1](lambda x: x * x)The map transformation applies a function to each element of the RDD.
Fix the error in the code to count the number of elements in an RDD.
count = rdd.[1]()The count() action returns the number of elements in an RDD.
Fill both blanks to create a dictionary of word counts using Spark RDD transformations.
word_counts = rdd.[1](lambda line: line.split()).[2](lambda word: (word, 1)).reduceByKey(lambda a, b: a + b).collectAsMap()
flatMap splits lines into words, then map creates (word, 1) pairs for counting.
Fill all three blanks to filter an RDD for words longer than 3 characters, convert to uppercase, and collect results.
result = rdd.[1](lambda word: len(word) [2] 3).[3](lambda word: word.upper()).collect()
filter selects words longer than 3, map converts them to uppercase.