-1

I am practicing some spark code, and starting itself I am stuck with below error.

newRDD = sc.textFile("/user/cloudera/sqoop-import/products")

17/03/15 20:41:31 INFO storage.MemoryStore: Block broadcast_1 stored as values in memory (estimated size 198.0 KB, free 419.3 KB) 17/03/15 20:41:31 INFO storage.MemoryStore: Block broadcast_1_piece0 stored as bytes in memory (estimated size 23.3 KB, free 442.7 KB) 17/03/15 20:41:31 INFO storage.BlockManagerInfo: Added broadcast_1_piece0 in memory on 192.168.50.129:49855 (size: 23.3 KB, free: 530.2 MB) 17/03/15 20:41:31 INFO spark.SparkContext: Created broadcast 1 from textFile at NativeMethodAccessorImpl.java:-2

for i in newRDD:
...     print(i)
... 

Traceback (most recent call last): File "", line 1, in TypeError: 'RDD' object is not iterable

Akash Sethi
  • 2,284
  • 1
  • 20
  • 40
  • 4
    Possible duplicate of [How do I iterate RDD's in apache spark (scala)](http://stackoverflow.com/questions/25914789/how-do-i-iterate-rdds-in-apache-spark-scala) – Elliott Frisch Mar 16 '17 at 03:49

2 Answers2

0

My bad. I did not use any action on data. Only transformation will not get data to the driver program, as all of it is a lazy evaluation.

0

restart your Linux and and try like this

for(el <- newRDD){
println(el)
}

the RDDs are not numbers to iterate, you most use loop like above for accessing each element

AliSafari186
  • 113
  • 9