

{"id":1309,"date":"2016-12-23T16:10:20","date_gmt":"2016-12-23T16:10:20","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=1309"},"modified":"2018-11-20T15:11:58","modified_gmt":"2018-11-20T09:41:58","slug":"apache-spark-map-vs-flatmap","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/","title":{"rendered":"Apache Spark Map vs FlatMap Operation"},"content":{"rendered":"<h2>1. Objective<\/h2>\n<p>In this <strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-tutorial\/\">Apache Spark<\/a><\/strong> tutorial, we will discuss the comparison between Spark Map vs FlatMap Operation. Map and FlatMap are\u00a0the <strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\">transformation operations in Spark<\/a><\/strong>.<strong>\u00a0<\/strong><strong>Map()<\/strong> operation applies to each element of<a href=\"http:\/\/data-flair.training\/blogs\/resilient-distributed-datasets-rdd-apache-spark\/\"><strong> RDD<\/strong><\/a> and it returns the result as new RDD. In the Map, operation developer can define his own custom business logic. While<strong> FlatMap()<\/strong> is similar to Map, but FlatMap allows returning 0, 1 or more elements from map function.<\/p>\n<p>In this blog, we will discuss how to perform map operation on RDD and how to process data using FlatMap operation. This tutorial also covers what is map operation, what is a flatMap operation, the difference between map() and flatMap() transformation in Apache Spark with examples. We will also see Spark map and flatMap example in<strong> Scala<\/strong> and <strong>Java<\/strong> in this Spark tutorial.<\/p>\n<p>So, let&#8217;s start Spark Map vs FlatMap function.<\/p>\n<div id=\"attachment_42949\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42949\" class=\"size-full wp-image-42949\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg\" alt=\"Apache Spark Map vs FlatMap Operation\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-42949\" class=\"wp-caption-text\">Apache Spark Map vs FlatMap Operation<\/p><\/div>\n<p><a href=\"http:\/\/data-flair.training\/blogs\/spark-installation-ubuntu\/\"><strong>\u00a0Do you know How to install and configure Apache Spark<\/strong>?<\/a><\/p>\n<h2>2. Difference between Spark Map vs FlatMap Operation<\/h2>\n<p>This section of the Spark tutorial provides the details of Map vs FlatMap operation in Apache Spark with examples in\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/why-you-should-learn-scala-introductory-tutorial\/\">Scala<\/a><\/strong> and <strong>Java<\/strong> programming languages.<\/p>\n<h3>i. Spark Map Transformation<\/h3>\n<p>A <strong>map<\/strong> is a transformation operation in <strong>Apache Spark.<\/strong>\u00a0It\u00a0applies to each element of<strong> RDD<\/strong> and it returns the result as new RDD. In the Map, operation developer can define his own custom business logic. The same logic will be applied to all the elements of RDD.<\/p>\n<p>Spark Map function takes one element as input process it according to custom code (specified by the developer) and returns one element at a time.\u00a0Map transforms an <strong>RDD<\/strong> of length N into another RDD of length N. The input and output RDDs will typically have the same number of records.<\/p>\n<div id=\"attachment_1310\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/spark-map-transformation-operation.gif\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1310\" class=\"wp-image-1310 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/spark-map-transformation-operation.gif\" alt=\"apache spark map transformation operation\" width=\"600\" height=\"338\" \/><\/a><p id=\"caption-attachment-1310\" class=\"wp-caption-text\">Apache Spark map transformation operation<\/p><\/div>\n<h4><strong>a. Map Transformation Scala Example<\/strong><\/h4>\n<p><strong>Create RDD<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val data = spark.read.textFile(\"INPUT-PATH\").rdd<\/pre>\n<p>Above statement will create an RDD with name data. Follow this guide to learn more<strong> <a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\">ways to create RDDs<\/a> <\/strong>in Apache Spark<strong>.<\/strong><\/p>\n<p><strong>Map Transformation-1<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val newData = data.map (line =&gt; line.toUpperCase() )<\/pre>\n<p>Above the map, a transformation will convert each and every record of RDD to upper case.<\/p>\n<p><strong>Map Transformation-2<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val tag = data.map {line =&gt; {\r\nval xml = XML.loadString(line)\r\nxml.attribute(\"Tags\").get.toString()\r\n}\r\n}<\/pre>\n<p>Above the map, a transformation will parse XML and collect Tag attribute from the XML data. Overall the map operation is converting XML into a structured format.<\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/java-tutorial\/\">Follow this link to know about Java Programming Language<\/a><\/strong><\/p>\n<h4>b. Map Transformation Java Example<\/h4>\n<p><strong>Create RDD<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">JavaRDD&lt;String&gt; linesRDD = spark.read().textFile(\"INPUT-PATH\").javaRDD();<\/pre>\n<p>Above statement will create an RDD with name\u00a0lines RDD.<\/p>\n<p><strong>Map Transformation<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">JavaRDD&lt;String&gt; newData = linesRDD.map(new Function&lt;String, String&gt;() {\r\npublic String call(String s) {\r\nString result = s.trim().toUpperCase();\r\nreturn result;\r\n}\r\n});<\/pre>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/scala-spark-shell-commands\/\">We recommend you to read &#8211;\u00a0Spark Shell Commands to Interact with Spark-Scala<\/a><\/strong><\/p>\n<h3>ii. Spark FlatMap Transformation Operation<\/h3>\n<p>Let&#8217;s now discuss flatMap() operation in Apache Spark-<\/p>\n<div id=\"attachment_1311\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/spark-flatmap-transformation-operation.gif\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1311\" class=\"wp-image-1311 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/spark-flatmap-transformation-operation.gif\" alt=\"apache spark flatmap transformation operation\" width=\"600\" height=\"338\" \/><\/a><p id=\"caption-attachment-1311\" class=\"wp-caption-text\">Apache Spark flatMap transformation operation<\/p><\/div>\n<p>A<strong> flatMap<\/strong> is a transformation operation. It applies to each element of RDD and it returns the result as new RDD. It is similar to Map, but FlatMap allows returning 0, 1 or more elements\u00a0from map function. In the FlatMap operation, a developer can define his own custom business logic. The same logic will be applied to all the elements of the RDD.<\/p>\n<p>A FlatMap function takes one element as input process it according to custom code (specified by the developer) and returns 0\u00a0or more element at a time. flatMap() transforms an RDD of length N into another RDD of length M.<\/p>\n<h4><strong>a.\u00a0FlatMap Transformation Scala Example<\/strong><\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val result = data.flatMap (line =&gt; line.split(\" \") )<\/pre>\n<p>Above flatMap transformation will convert\u00a0a line into words. One word will be an individual\u00a0element of the newly created RDD.<\/p>\n<p><strong>Learn to <a href=\"https:\/\/data-flair.training\/blogs\/create-spark-scala-project\/\">Create Spark project in Scala with Eclipse<\/a><\/strong><\/p>\n<h4><strong>b. FlatMap Transformation Java Example<\/strong><\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">JavaRDD&lt;String&gt; result = data.flatMap(new FlatMapFunction&lt;String, String&gt;() {\r\npublic Iterator&lt;String&gt; call(String s) {\r\nreturn Arrays.asList(s.split(\" \")).iterator();\r\n} });<\/pre>\n<p>Above flatMap transformation will convert\u00a0a line into words. One word will be an individual\u00a0element of the newly created RDD.<\/p>\n<h2>3. Conclusion<\/h2>\n<p>Hence, from the comparison between Spark map() vs flatMap(), it is clear that Spark map function expresses a one-to-one transformation. It transforms each element of a collection into one element of the resulting collection. While Spark flatMap function expresses a one-to-many transformation. It transforms each element to 0 or more elements.<\/p>\n<p>Please leave a comment if you like this post or have any query about Apache Spark map vs flatMap function.<\/p>\n<p><strong>See Also-<\/strong><\/p>\n<ul>\n<li><strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-hadoop-compatibility\/\">Apache Spark compatibility with Hadoop<\/a><\/strong><\/li>\n<\/ul>\n<p><strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Apache_Spark\">Reference for Spark<\/a><\/strong><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1357,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Apache_Spark&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250922221612\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Apache_Spark&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 05:27:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 10:08:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-15 10:54:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 15:58:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-21 22:36:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-25 05:31:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-28 12:45:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-31 14:24:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 17:46:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-07 06:00:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-10 18:44:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-14 03:23:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-17 07:55:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-20 08:53:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-23 13:06:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-26 19:31:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-30 03:59:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-02 04:29:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-05 06:45:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-08 15:14:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-11 17:11:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-14 17:21:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 19:54:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-21 15:31:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 16:57:05&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-02-27 17:43:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-02 18:00:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-06 08:59:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-09 10:45:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 12:05:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-15 13:52:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-18 16:22:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-22 02:26:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-25 06:42:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-28 13:17:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-31 19:34:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 21:06:08&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-07 13:23:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 15:12:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-14 01:00:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-17 15:03:23&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-20 17:12:48&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-23 18:14:30&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-26 23:59:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-30 03:29:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-03 03:48:13&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-06 06:11:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-09 10:25:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-12 12:20:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-15 15:48:18&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-19 00:06:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-22 12:24:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 12:59:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-28 18:04:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-01 07:34:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-04 09:52:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-07 13:28:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-10 15:46:34&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-14 08:05:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-18 01:16:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-21 13:30:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-24 15:27:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-27 17:21:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-01 06:45:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-04 09:53:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-08 00:36:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-11 08:27:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-14 08:44:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-17 13:39:30&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-17 13:39:30&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Objective In this Apache Spark tutorial, we will discuss the comparison between Spark Map vs FlatMap Operation. Map and FlatMap are\u00a0the transformation operations in Spark.\u00a0Map() operation applies to each element of RDD and&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":42949,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[896,4733,4734,8532,8533,13021,13084,16617,13142,14897],"class_list":["post-1309","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spark","tag-apache-spark","tag-flatmap-spark","tag-flatmap-transformation","tag-map-transformation","tag-map-vs-flatmap","tag-spark","tag-spark-map","tag-spark-map-vs-flatmap","tag-spark-tutorial","tag-transformation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apache Spark Map vs FlatMap Operation - DataFlair<\/title>\n<meta name=\"description\" content=\"Tutorial for Apache Spark Map vs FlatMap operation, comparison between spark map &amp; flatMap function, Java Map &amp; flatMap,Scala map &amp; flatMap example in spark\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Spark Map vs FlatMap Operation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Tutorial for Apache Spark Map vs FlatMap operation, comparison between spark map &amp; flatMap function, Java Map &amp; flatMap,Scala map &amp; flatMap example in spark\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-23T16:10:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-20T09:41:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apache Spark Map vs FlatMap Operation - DataFlair","description":"Tutorial for Apache Spark Map vs FlatMap operation, comparison between spark map & flatMap function, Java Map & flatMap,Scala map & flatMap example in spark","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/","og_locale":"en_US","og_type":"article","og_title":"Apache Spark Map vs FlatMap Operation - DataFlair","og_description":"Tutorial for Apache Spark Map vs FlatMap operation, comparison between spark map & flatMap function, Java Map & flatMap,Scala map & flatMap example in spark","og_url":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2016-12-23T16:10:20+00:00","article_modified_time":"2018-11-20T09:41:58+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Apache Spark Map vs FlatMap Operation","datePublished":"2016-12-23T16:10:20+00:00","dateModified":"2018-11-20T09:41:58+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/"},"wordCount":704,"commentCount":39,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg","keywords":["apache spark","flatmap spark","flatmap transformation","map transformation","map vs flatmap","Spark","spark map","Spark map vs Flatmap","spark tutorial","transformation"],"articleSection":["Apache Spark Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/","url":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/","name":"Apache Spark Map vs FlatMap Operation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg","datePublished":"2016-12-23T16:10:20+00:00","dateModified":"2018-11-20T09:41:58+00:00","description":"Tutorial for Apache Spark Map vs FlatMap operation, comparison between spark map & flatMap function, Java Map & flatMap,Scala map & flatMap example in spark","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/12\/Apache-Spark-Map-vs-FlatMap-Operation-01.jpg","width":1200,"height":628,"caption":"Apache Spark Map vs FlatMap Operation"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-map-vs-flatmap\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Apache Spark Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/spark\/"},{"@type":"ListItem","position":3,"name":"Apache Spark Map vs FlatMap Operation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/1309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=1309"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/1309\/revisions"}],"predecessor-version":[{"id":42950,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/1309\/revisions\/42950"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/42949"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=1309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=1309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=1309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}