Basic Actions
24
nums = sc.parallelize([5, 1, 3, 2])
nums.collect() # => [5, 1, 3, 2] # Retrieve RDD contents as a local collection à Results must fit
in memory on the local machine
nums.take(2) # => [5, 1] # Return first K elements
nums.takeOrdered(4) # => [1, 2, 3, 5] # Return first K elements ordered
nums.takeOrdered(4, lamda n:-n) # => [5, 3, 2, 1]
nums.count() # => 4 # Count number of elements
# Merge elements with an associative function
nums.reduce(lambda x, y: x + y) # => 12
nums.saveAsTextFile(“hdfs://file.txt”)