<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Talent Origin on Medium]]></title>
        <description><![CDATA[Stories by Talent Origin on Medium]]></description>
        <link>https://medium.com/@talentorigin?source=rss-e81f8bb37df6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8fiCTI4a9AYz8Hb8SZ9lOQ.jpeg</url>
            <title>Stories by Talent Origin on Medium</title>
            <link>https://medium.com/@talentorigin?source=rss-e81f8bb37df6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:06:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@talentorigin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Spark UDF (User Defined Function) Using Scala — Approach 1]]></title>
            <link>https://medium.com/@talentorigin/spark-udf-user-defined-function-using-scala-approach-1-be2463867528?source=rss-e81f8bb37df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/be2463867528</guid>
            <category><![CDATA[udf]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[user-defined-functions]]></category>
            <category><![CDATA[spark-2]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Talent Origin]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 06:22:29 GMT</pubDate>
            <atom:updated>2019-01-27T06:22:29.757Z</atom:updated>
            <content:encoded><![CDATA[<p>Spark UDF (User Defined Function) Using Scala — Approach 1</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0apEa5-p76k%3Fstart%3D14%26feature%3Doembed%26start%3D14&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0apEa5-p76k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0apEa5-p76k%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc5818302079bb4bfea5c4469934c602/href">https://medium.com/media/bc5818302079bb4bfea5c4469934c602/href</a></iframe><p>This blog is text version of above video lecture from my <a href="https://www.youtube.com/c/TalentOrigin">YouTube</a> Channel, along with complete <a href="https://www.youtube.com/watch?v=wSNPPhqrVtw&amp;list=PLlL9SaZVnVgizWn2Gr_ssHExaQUYik2vp">Spark Tutorial</a>.</p><p>We will learn one of the approach of creating Spark UDF where we can use the UDF with spark’s DataFrame/Dataset API.</p><p>Spark provides SQL functions under <a href="https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.functions$">org.apache.spark.sql.functions</a>. There are different variety of functions provided by spark like Aggregate functions, Math functions, Date time functions, Collection functions, String functions etc., but there will be times in our projects where none of these functions will solve the purpose. So, to solve our use case we have to write custom functions. Though we write our custom functions we should be able to use them in our spark code. To solve this purpose spark provides users an option for defining custom functions which are called User Define Functions — UDF.</p><p>We have to follow below steps for writing an Spark UDF:</p><ol><li>Define a function in scala</li><li>Create a UDF to call the function created in step 1</li><li>Use UDF created in step 2 with spark dataframe/dataset API</li></ol><p>Let’s consider a simple problem statement. I have a dataset of stocks which have columns “CLOSE” and “PREVCLOSE”. To find the difference between “PREVCLOSE” and “CLOSE” of all stocks in my dataset and add the difference as a new column with name “DIFFCLOSE”.</p><p>Let’s consider a simple problem statement. I have a dataset of stocks which have columns “CLOSE” and “PREVCLOSE”. To find the difference between “PREVCLOSE” and “CLOSE” of all stocks in my dataset and add the difference as a new column with name “DIFFCLOSE”.</p><p>Now let’s proceed with UDF creation.</p><p><strong>Step 1: Define a function in Scala</strong></p><p>If you observe the use case the basic thing we have to find out is difference between 2 numbers, which isn’t a big task right? So, let’s write a function which takes 2 numbers and returns the difference of 2 numbers.</p><pre>def numberDifference(num1: Double, num2: Double): Double = {<br>    num1 - num2<br>}</pre><p>this doesn’t seem tough right? let’s proceed to step 2</p><p><strong>Step 2: Creating an UDF</strong></p><p>Now that we have our scala function handy which takes two numbers and returns the difference between the numbers, let us create a UDF for this function.</p><pre><strong>import </strong>org.apache.spark.sql.functions.udf</pre><pre>val numberDifferenceUDF = udf[Double, Double, Double](numberDifference)</pre><p>This also looks quite simple right? ‘udf’ is the function provided under <a href="https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.functions$">org.apache.spark.sql.functions</a> which is used to created user defined function and this ‘udf’ takes parameters with in square braces([]). Within square braces first argument takes return type of the scala function and the following arguments are datatypes of scala function in the same order as the scala function takes. This is followed by parentheses () which takes name of the scala function to be used. Remember not to give () to the scala function mentioned here you just have to pass the function name without parentheses.</p><p>That’s it we have defined an UDF which can be used in spark code. Doesn’t seem to be so complex right?</p><p><strong>Step 3: Using UDF with spark dataframe</strong></p><p>Now that we have user defined function ready let’s use it with spark dataframe. Let’s first read the data:</p><pre>val data = spark.read.option(&quot;inferSchema&quot;,&quot;true&quot;)<br>                     .option(&quot;header&quot;,&quot;true&quot;)<br>                     .csv(&quot;nse-stocks-data.csv&quot;)</pre><p>Now let’s create a new column “DIFFCLOSE” which holds the difference of columns “PREVCLOSE” and “CLOSE”</p><pre><strong>val </strong>diffColumnData = data.withColumn(&quot;DIFFCLOSE&quot;,diffCalculationUDF(data(&quot;PREVCLOSE&quot;), data(&quot;CLOSE&quot;)))</pre><pre>diffColumnData.show()</pre><p>Let’s put it all together.</p><pre><strong>import </strong>org.apache.spark.sql.SparkSession<br><strong>import </strong>org.apache.spark.sql.functions.udf<br><br><strong>object </strong>UdfExample {<br>  <strong>def </strong>main(args: Array[String]): Unit = {<br>    <strong>val </strong>spark  = SparkSession<br>      .<em>builder</em>()<br>      .master(&quot;local&quot;)<br>      .appName(&quot;Spark UDF Using Curry Functions&quot;)<br>      .getOrCreate()<br><br>    <strong>val </strong>data = spark.read<br>      .option(&quot;inferSchema&quot;, &quot;true&quot;)<br>      .option(&quot;header&quot;, &quot;true&quot;)<br>      .csv(&quot;nse-stocks-data.csv&quot;)<br><br>    <strong>val </strong>diffCalculationUDF = <em>udf</em>[Double, Double, Double](<em>diffCalculation</em>)<br><br>    <strong>val </strong>diffColumnData = data.withColumn(&quot;DIFFCLOSE&quot;,diffCalculationUDF(data(&quot;PREVCLOSE&quot;), data(&quot;CLOSE&quot;)))<br>    diffColumnData.show()<br>  }<br><br>  <strong>def </strong>diffCalculation(num1: Double, num2: Double): Double = num1 - num2<br>}</pre><p>I have composed two examples for UDF and code is checked in to GitHub under <a href="https://github.com/TalentOrigin/spark-course/blob/master/src/main/scala/advanced/spark/SparkUDFExample.scala">here</a> and <a href="https://github.com/TalentOrigin/gcp-spark-tutorial/blob/master/src/main/scala/com/talentorigin/spark/on/gcp/UdfExampleApproach1.scala">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be2463867528" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Apache Spark Cluster On Google Cloud Platform (GCP)]]></title>
            <link>https://medium.com/@talentorigin/creating-apache-spark-cluster-on-google-cloud-platform-gcp-9a5d8b9c0ffb?source=rss-e81f8bb37df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a5d8b9c0ffb</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[apache-spark]]></category>
            <dc:creator><![CDATA[Talent Origin]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 18:02:58 GMT</pubDate>
            <atom:updated>2018-09-19T18:02:58.544Z</atom:updated>
            <content:encoded><![CDATA[<p>Hadoop and Spark has gained a huge momentum in the market for working with Big data. There is lot of requirement in IT industry for Apache spark but there are very few potential candidates in the market. Where do you think gap is? Usually if any new programming languages or new frameworks comes into market it takes hardly a year or two for any decent resource to properly get trained on the skill and get a job. But Spark came into market more than 4.5 years but still industry is facing lack of potential resources. I think one of the main reason for this is due infrastructure requirement for learning the technology properly. Unlike any programming language Hadoop or Spark won’t work on a single machine so while developing applications we have to think in terms of distributed computing. To develop distributed applications it always helps to have distributed environment to learn so that anyone can master the skills that are required. Even though spark can run in standalone mode, the way it works in the distributed environments will be different. More over to troubleshoot realtime issues you definitely should have anunderstanding and working knowledge on running spark application in distributed environment. As most of the enthusiasts don’t have proper infrastructure setup it’s getting difficult for them to get used to realtime troubleshooting and hence there is a gap in the market for this skill.</p><p>Now a days we have many cloud computing platforms like AWS, Azure, GCP etc., We can leverage these cloud platforms for creating clusters and tryout how distributed computing works. But to create clusters like real time it’s costs money in these cloud services. Even though free tiers provide 1 year free subscription to the cloud we will get bare minimum resources to work with.</p><p>I have recently tried GCP free tier for creating multi node Hadoop cluster using DataProc. I was able to create 4 Node cluster with 1 Master and 3 workers with 2 VCPUs and 7.5 Gigs of Memory for each node and it was absolutely free and of course your free google credit amount would be detected with small amount. Compared to charges with other Cloud service providers, its less.</p><p>I have made a dedicated video on creating GCP account and on creating a multi node Hadoop cluster using DataProc. You can checkout below YouTube video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FvqIEN8KSRMc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DvqIEN8KSRMc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FvqIEN8KSRMc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/16aa9fa1c2e8ee340eb0651f2b65bdcf/href">https://medium.com/media/16aa9fa1c2e8ee340eb0651f2b65bdcf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a5d8b9c0ffb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Spark Job in YARN mode from IDE]]></title>
            <link>https://medium.com/@talentorigin/running-spark-job-in-yarn-mode-from-ide-a547d58b2057?source=rss-e81f8bb37df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a547d58b2057</guid>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[eclipse]]></category>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[hadoop]]></category>
            <dc:creator><![CDATA[Talent Origin]]></dc:creator>
            <pubDate>Sun, 25 Feb 2018 17:46:51 GMT</pubDate>
            <atom:updated>2018-02-26T15:47:13.316Z</atom:updated>
            <content:encoded><![CDATA[<p>Often while developing spark jobs on an IDEs like Eclipse or IntelliJ, we will test the jobs in “local” mode. While developing jobs to run clusters to work with distributed data its just not enough to test the job in local mode running in your local machine. Jobs which run in local mode might not work as expected on the cluster in distributed environment and there might be many reasons for it.</p><p>When developing Spark application you can submit Spark Job to Hadoop cluster by setting spark master as Yarn from development environment which can be an IDE. There are two approaches for achieving this. In this story we will discuss approach one:</p><h3><strong>Approach One:</strong></h3><p>Passing all configurations to Spark Job using “config” method of SparkSession. Using this config method you can set any configuration related to Hadoop, Yarn, MapReduce, Hive, HBase and of-course Spark. With this approach you can you have control on which property to set. Below is the sample code in scala:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48f1e485023c17ae6d173d375e360700/href">https://medium.com/media/48f1e485023c17ae6d173d375e360700/href</a></iframe><p>All jars which are used in the spark job can be placed in HDFS common location and specify configuration parameter usingspark.yarn.jars property as shown in the line 5 . This property is a basic ingredient for running your Spark job successfully in yarn mode from eclipse.</p><p>Checkout below YouTube video for step by step walk through and common issues you might face while running the spark job in yarn from eclipse using this approach:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FdN60fkxABZs%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdN60fkxABZs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FdN60fkxABZs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/964461ac49741f494b3d29ceab321e04/href">https://medium.com/media/964461ac49741f494b3d29ceab321e04/href</a></iframe><p>We will discuss Approach 2 for running spark job in Yarn mode from eclipse in my next story.</p><h3>Stay Connected…</h3><p>Subscribe to <a href="https://www.youtube.com/channel/UCidQrtaWcEJ-1E-ikTP35qg">TalentOrigin</a> Channel for more Video Tutorials</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a547d58b2057" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@ Reading a CSV File in Spark 2.0]]></title>
            <link>https://medium.com/@talentorigin/reading-a-csv-file-in-spark-2-0-ff135da458e8?source=rss-e81f8bb37df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff135da458e8</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[csv]]></category>
            <dc:creator><![CDATA[Talent Origin]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 03:32:17 GMT</pubDate>
            <atom:updated>2018-02-25T06:03:36.399Z</atom:updated>
            <content:encoded><![CDATA[<p>YouTube Video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLlL9SaZVnVgizWn2Gr_ssHExaQUYik2vp&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYjddv2F5Cgo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYjddv2F5Cgo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/16ccdc7fd21864a39cbd12dbd93eeb71/href">https://medium.com/media/16ccdc7fd21864a39cbd12dbd93eeb71/href</a></iframe><p>CSV files are Comma Separated Values are flat files which are delimited by Comma’s. Prior to Spark 2.0 working with CSV files in Spark was supported using <a href="https://github.com/databricks/spark-csv">databricks csv package</a>. CSV file support is integrated with Spark starting from version 2.0.</p><p>Reading a CSV files converts the file into a DataFrame. Spark also provides different variety of options for working with CSV files like specifying header, inferring schema, charset support or specifying type of delimiter etc., Using spark CSV we not only read comma separated files we can read a file with any single character delimiter.</p><p>In this post let us see how we can read a CSV file in Spark 2.0 and few important options which are useful. Firstly we have to create a spark session as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*lNEsaNbdn4mnL0Na-9Ox3Q.png" /><figcaption>Creating a SparkSession in Spark 2.0</figcaption></figure><p>Once we have spark session available, the simplest way of reading a CSV file is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*vLixmVNHaOoQT2VEkR5FvA.png" /><figcaption>Creating a DataFrame with a CSV File</figcaption></figure><p>Above statement reads a CSV file and creates a dataframe. To see the contents of the dataframe we can use show() method on csvDF. output would something similar to the below output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*8ioDxSa7J5jNMHaV5n4BoA.png" /></figure><p>You can see there are 5 columns in our CSV file and Spark has given default column names as _c0, _c1,..,_c4 but my CSV file has header, meaning first line of my CSV file refers to the column names of the data but not the actual data. Now if you observe closely you can see the first row of the output actually is not the data but its the names of the columns in the file. But default spark has not identified the header in the CSV file.</p><p>To make spark identify the header in the CSV file we can use option() and specify that header is available in the file. This can be achieved as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*pJrCKHCPVoJOrcMOeqsywQ.png" /><figcaption>Reading CSV files with Option</figcaption></figure><p>lets see how the output looks with show:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*w6Uw3Bymac_TTcmduVdqPQ.png" /></figure><p>now you can see spark has identified the column names properly and assigned the columns names which are in the file instead of giving its own column names.</p><p>Now lets see the schema and datatypes of the dataframe which we have loaded. To print the schema we can use printSchema() method form dataframe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*zHsm3f39ughogZUO7SIf2g.png" /><figcaption>Default schema of CSV file</figcaption></figure><p>In the output of printSchema() you can see the column name and datatype of the column name. Also, you can see the nullable property which is either true or false. nullable true means, column can have null values, if nullable is set to false that means column can not have null value.</p><p>Lets observe the output of show(). You can notice there are numeric values for the columns Year and Count. But printSchema() output shows the datatype of these columns as String. This is because spark by default considers all the contents that it read from the file as String.</p><p>You can also force spark to infer the schema for the loaded file. Spark reads the file and assigns appropriate datatype to the columns based on the data that column consists. You can force spark to infer schema by setting an option inferSchema as true. Lets try to see the datatypes of the columns after inferring the schema:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*__VVN5GMsL2U7l4SZKpSqg.png" /><figcaption>Inferring Schema while reading a CSV file</figcaption></figure><p>Now you can see that spark has inferred the schema and treated columns Year and Count as Integer datatypes.</p><p>In the above example we have set the options header and inferSchema with two option methods. Instead, we can use another method called options() and pass a map of key, value pairs as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*9XUMV06ZDMtBUkkzgDtoQQ.png" /></figure><p>If we have more options to set, then instead of using one option method for property we can create a Map of key value pairs and pass that map to the options() method.</p><p>Reading header and inferring schema are the basic operations that are usually performed on a CSV file.</p><p>Checkout YouTube video for reading CSV files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff135da458e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reading Compressed Files With Spark 2.0 -Part -1]]></title>
            <link>https://medium.com/@talentorigin/reading-compressed-files-with-spark-2-0-part-1-c25c5ea7ad93?source=rss-e81f8bb37df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c25c5ea7ad93</guid>
            <category><![CDATA[zip-file]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Talent Origin]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 03:07:13 GMT</pubDate>
            <atom:updated>2018-01-24T03:07:13.310Z</atom:updated>
            <content:encoded><![CDATA[<h3>WORKING WITH GZIP</h3><p>It is very common to deal with compressed files while working with bigdata. There are different compression formats that are available. Spark supports all compression formats that are supported by Hadoop.</p><p>In this blog we will see how to load and work with Gzip compressed files with Apache Spark 2.0. The reason I am demonstrating compressed file reading with Gzip files is because of the reason that Gzip compression files are not splittable, meaning when a 10GB sized Gzip file is stored in a hadoop cluster, entire 10GB file will be stored on one single node and only one executor can work on entire file and it is challenging to get performance using Gzip files. So, Gzip file format is not a suggestible compression format as far as distributed processing is concerned. Lets see number of ways we can read a Gzip file.</p><p>By default spark supports Gzip file directly, so simplest way of reading a Gzip file will be with textFile method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*4zThTuNS8z9VFT1gG5PalA.png" /><figcaption>Reading a zip file using textFile in Spark</figcaption></figure><p>Above code reads a Gzip file and creates and RDD. textFile method can also read a directory and create an RDD with the contents of the directory.</p><p>If you want to read files in a directory and build a pairRDD with key-value pairs wholeTextFiles can be used. key will be name of the file and value will be contents of the file. wholeTextFiles can be used to read Gzip files as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*UZQcUYqPSPEmNoOjH6P9MQ.png" /><figcaption>Reading Zip Files with wholeTextFiles Method in Spark</figcaption></figure><p>With the above code you will be creating a pairRDD, we can work with pairRDD as below and extract fileNames:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*Ys_wwHXBAS67mUJ0ndDBog.png" /><figcaption>Creating a PairedRDD and Accessing file names in the directory</figcaption></figure><p>in the above example, fileName in the case is key and its corresponding value, i.e., contents of the file will be in contents. Contents of the files can be accessed as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*DX6vl5mikz6MXrglqv5pxg.png" /><figcaption>Reading contents of zip file</figcaption></figure><p>above statement gives all the contents of the directory as a single RDD[String], meaning all files are merged together to give a single RDD. Once we have RDD[String] available we can convert RDD into DataFrame by converting RDD[String] to RDD[Row] as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*9aNGlID0zq47Q3714dj3cA.png" /><figcaption>Converting lines read from zip files into RDD</figcaption></figure><p>rowRDD is RDD[Row]. Let’s walk through code snippet, we are iterating through each line of lines RDD which is RDD[String]. Each line is split based on the delimiter, in my case its “,” returning an Array of line. Now we are using fromSeq() method of Row object to return an Row object of each line.</p><p>Above shown are basic ways to read an Gzip files in Spark 2.0. In my next blog we will see advanced ways of reading Gzip files in Spark.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c25c5ea7ad93" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>