Options
- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Explain foreach() operation in apache spark
Labels:
- Labels:
-
Apache Spark
Explorer
Created ‎08-21-2017 05:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1 REPLY 1
Explorer
Created ‎08-21-2017 05:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
foreach() operation is an action.
> It do not return any value.
> It executes input function on each element of an RDD.
From :
http://data-flair.training/blogs/rdd-transformations-actions-apis-apache-spark/#39_Foreach
It executes the function on each item in RDD. It is good for writing database or publishing to web services. It executes parameter less function for each data items.
Example:
val mydata = Array(1,2,3,4,5,6,7,8,9,10)
val rdd1 = sc.parallelize(mydata)
rdd1.foreach{x=>println(x)}
OR
rdd1.foreach{println}
Output:
1
2
3
4
5
6
7
8
9
10
