

{"id":2779,"date":"2017-06-09T06:44:09","date_gmt":"2017-06-09T06:44:09","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=2779"},"modified":"2020-01-23T17:24:15","modified_gmt":"2020-01-23T11:54:15","slug":"apache-spark-interview-questions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/","title":{"rendered":"50 Frequently Asked Apache Spark Interview Questions"},"content":{"rendered":"<h2>1. Apache Spark Interview Questions &#8211; Objective<\/h2>\n<p><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-tutorial\/\"><strong>Apache Spark<\/strong><\/a> is prevailing\u00a0because of its capability to handle real-time streaming and processing big data faster than <a href=\"http:\/\/data-flair.training\/blogs\/hadoop-introduction-tutorial-quick-guide\/\"><strong>Hadoop<\/strong><\/a> <strong><a href=\"http:\/\/data-flair.training\/blogs\/hadoop-mapreduce-introduction-tutorial-comprehensive-guide\/\">MapReduce<\/a><\/strong>. As the demand for Spark developers\u00a0are expected to grow in a lightning fast manner, it is the golden time to polish your Apache Spark knowledge and build up your\u00a0career as a <strong><a href=\"http:\/\/data-flair.training\/blogs\/data-analytics-comprehensive-guide\/\">data analytics<\/a><\/strong> professional, <strong><a href=\"http:\/\/data-flair.training\/blogs\/skills-needed-to-become-a-data-scientist\/\">data scientist<\/a><\/strong> or<strong><a href=\"http:\/\/data-flair.training\/blogs\/why-learn-big-data-use-cases\/\"> big data <\/a><\/strong>developer. This guide on spark interview questions and answers will help you to improve the skills that will shape you for Spark developer job roles. This section contains top 50 Apache Spark Interview Questions and Answer. Hope these questions will help you to crack the Spark interview. Happy Job Hunting!<\/p>\n<p>So, let&#8217;s start exploring Apache Spark Interview Questions.<\/p>\n<div id=\"attachment_42320\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42320\" class=\"size-full wp-image-42320\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg\" alt=\"50 Frequently Asked Apache Spark Interview Questions\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-42320\" class=\"wp-caption-text\">50 Frequently Asked Apache Spark Interview Questions<\/p><\/div>\n<h2>2. Top 50 Apache Spark Interview Questions and Answers<\/h2>\n<p>Let&#8217;s proceed further with Apache Spark Interview Questions and Answer-<\/p>\n<p><strong>1)\u00a0What is Apache Spark? What is the reason behind the evolution of this framework?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Spark<\/a><\/strong>\u00a0is an open source big data framework. It has an expressive APIs to allow big data professionals to efficiently execute streaming as well as the batch. Apache Spark provides faster and more general data processing platform engine. It basically designed for fast computation and developed at UC Berkeley in 2009. Spark is an Apache project which is also call as \u201clighting fast cluster computing\u201c. It distributes data in a file system across the cluster, and process that data in parallel. Spark covers a wide range of workloads like batch applications, iterative algorithms, interactive queries and streaming. It lets you write an application in Java, Python or Scala.<\/p>\n<p>It was developed to overcome the limitations of\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/hadoop-mapreduce-introduction-tutorial-comprehensive-guide\/\" rel=\"nofollow\">MapReduce<\/a><\/strong>\u00a0cluster computing paradigm. Spark keeps things in memory whereas map reduces keep shuffling things in and out of disk. It allows to cache data in memory which is beneficial in iterative algorithm those used in machine learning.<\/p>\n<p>Spark is easier to develop as it knows how to operate on data. It supports SQL queries, streaming data as well as graph data processing. Spark doesn\u2019t need Hadoop to run, it can run on its own using other storages like Cassandra, S3 from which spark can read and write. In terms of speed spark run programs up to 100x faster in memory or 10x faster on disk than Map Reduce.<\/p>\n<p><strong>2)\u00a0Explain the features of Apache Spark because of which it is superior to Apache MapReduce?<\/strong><\/p>\n<p><strong>Ans.\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/hadoop-introduction-tutorial-quick-guide\/\" rel=\"nofollow\">Hadoop<\/a><\/strong>\u00a0is designed for batch processing. Batch processing is very efficient in the processing of high volume data.<br \/>\nHadoop MapReduce\u00a0is batch-oriented processing tool, it takes large dataset in the input, processes it and produces a result.<br \/>\nHadoop MapReduce adopted the batch-oriented model. Batch is essentially processing data at rest, taking a large amount of data\u00a0at once and producing output. MapReduce process is slower than spark because due to produce a lot of intermediary data.<\/p>\n<p>Spark\u00a0also supports batch processing system as well as stream processing.<\/p>\n<p><strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-comprehensive-guide\/\" rel=\"nofollow\">Spark streaming<\/a><\/strong>\u00a0processes data streams in micro-batches, Micro batches are an essentially collect and then process kind of<br \/>\ncomputational model. Spark processes faster than map reduces because it caches input data in memory by\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>.<\/p>\n<p><strong>3) Why is Apache Spark faster than Apache Hadoop?<\/strong><\/p>\n<p><strong>Ans.<\/strong>\u00a0Apache Spark\u00a0is faster than\u00a0Apache Hadoop\u00a0due to below reasons:<\/p>\n<ul>\n<li>Apache Spark provides\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-in-memory-computing\/\" rel=\"nofollow\">in-memory computing<\/a><\/strong>. Spark is designed to transform data In-memory and hence reduces time for disk I\/O. While\u00a0MapReduce\u00a0writes intermediate results back to Disk and reads it back.<\/li>\n<li>Spark utilizes\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\" rel=\"nofollow\">Direct Acyclic Graph<\/a><\/strong>\u00a0that helps to do all the optimization and computation in a single stage rather than multiple stages in the MapReduce model<\/li>\n<li>Apache Spark core is developed using\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/scala\/\" rel=\"nofollow\">SCALA<\/a><\/strong>\u00a0programming language which is faster than JAVA. SCALA provides inbuilt concurrent execution by providing immutable collections. While in JAVA we need to use Thread to achieve parallel execution.<\/li>\n<\/ul>\n<p><strong>4) List down the languages supported by Apache Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Apache Spark supports\u00a0Scala,\u00a0<strong>Python<\/strong>,\u00a0<strong>Java<\/strong>, and\u00a0R.<br \/>\nApache Spark is written in Scala. Many people use Scala for the purpose of development. But it also has API in Java, Python, and R.<\/p>\n<p><strong>5) What are the components of Apache Spark Eco-system? <\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong>Spark Core\u00a0<\/strong><\/p>\n<p>Spark Core is the base of Spark for parallel and distributed processing of huge datasets. It is in charge of all the essential I\/O functionalities, programming, and observance the roles on spark clusters. It is also responsible for task dispatching, and networking with different storage systems,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-fault-tolerance\/\" rel=\"nofollow\">fault tolerance<\/a><\/strong>, and economical memory management. Core uses special collection referred to as\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD (Resilient Distributed Datasets)<\/a><\/strong>.<\/p>\n<ul>\n<li><strong><a href=\"http:\/\/data-flair.training\/blogs\/spark-sql-tutorial\/\" rel=\"nofollow\">Spark SQL<\/a><\/strong><\/li>\n<\/ul>\n<p>SparkSQL is module\/component in Apache Spark that is employed to access structured and semi-structured information. It is a distributed framework that is tightly integrated with varied spark programming like\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/scala\/\" rel=\"nofollow\">Scala<\/a><\/strong>, Python, and Java. Spark SQL supports relative process in Spark programs via RDD further as on external data source. It is used for manipulating and taking information in varied formats. The means through that {we can|we will|we square measure able to} act with Spark SQL are SQL\/HQL,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-dataframe-tutorial\/\" rel=\"nofollow\">DataFrame<\/a><\/strong>\u00a0API, and Datasets API.<\/p>\n<p>The main abstraction in SparkSQL is information sets that act on structured data. It translates ancient SQL and HiveQL queries into Spark jobs creating Spark accessible wide. It supports real-time data analytics, data streaming SQL.<strong>SparkSQL defines 3 varieties of function:<\/strong><\/p>\n<ol>\n<li><strong>Built-in perform or user-defined function:<\/strong>\u00a0Object comes with some functions for column manipulation. Using Scala we are able to outlined user outlined perform.<\/li>\n<li><strong>Aggregate Function:<\/strong>\u00a0Operates on the cluster of rows and calculates one come back price per cluster.<\/li>\n<li><strong>Window Aggregate:<\/strong>\u00a0Operates on the cluster of rows and calculates one come back price every row in an exceeding cluster.<\/li>\n<\/ol>\n<p><strong>Different type of APIs for accessing SparkSQL:<\/strong><strong><br \/>\n<\/strong><\/p>\n<p><strong>SQL:\u00a0<\/strong>Executing SQL queries or\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/hive\/\" rel=\"nofollow\">Hive<\/a><\/strong>\u00a0queries, the result is going to become in the variety of DataFrame.<\/p>\n<ol>\n<li><strong>DataFrame:\u00a0<\/strong>It is similar to the relative table in SparkSQL and distributed the assortment of tabular information having rows and named column. It will perform filter, intersect, join, sort mixture and much more. DataFrames powerfully trusts\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">options of RDD<\/a><\/strong>. As it trusts RDD, it is\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/lazy-evaluation-in-apache-spark-guide\/\" rel=\"nofollow\">lazy evaluated<\/a><\/strong>\u00a0and immutable in nature.<br \/>\nDataFrameAPI is offered in Scala, Java, and Python.<\/li>\n<li><strong>Datasets API:\u00a0<\/strong>Dataset is new API to supply benefit of RDD because it is robust written and declarative in nature. Dataset is the assortment of object or records with the familiar schema. It should\u00a0model in some data structure. DataSets API offers improvement of DataFrames and static kind safety of Scala. We can convert information set to Data Frame.<\/li>\n<\/ol>\n<ul>\n<li><strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-comprehensive-guide\/\" rel=\"nofollow\">Spark Streaming<\/a><\/strong><\/li>\n<\/ul>\n<p>Spark Streaming is a light-weight API that permits developers to perform execution and streaming of information application. Discretized Streams kind the bottom abstraction in Spark Streaming. It makes use of an endless stream of {input information|input file|computer file} to method data in the time period. It leverages the quick programming capability of Apache Spark core to perform streaming analytics by ingesting information in mini-batches. Information in Spark Streaming accepts from varied information sources and live streams like Twitter, Apache Kafka, IoT Sensors, Amazon response, Apache Flume, etc. in an event-driven, fault-tolerant, and type-safe applications.<\/p>\n<ul>\n<li><strong>Spark element MLlib<\/strong><br \/>\nMLlib in Spark stands for machine learning (ML) library. Its goal is to form sensible machine learning effective, ascendible and straightforward. It consists of some learning algorithms and utilities, as well as classification, regression, clustering, collaborative filtering, spatial property reduction, further as lower-level improvement primitives and higher-level pipeline genus Apis.<\/li>\n<li><strong>GraphX<\/strong><br \/>\nGraphX, a distributed graph process framework on prime of Apache Spark. because it predicate on RDDs, that square measure immutable, graphs square measure immutable and so GraphX is unsuitable for graphs that require being updated, in addition to in an exceedingly transactional manner sort of a graph info.<\/li>\n<\/ul>\n<p><strong>For more details, please read\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-ecosystem-components\/\" rel=\"nofollow\">Apache Spark Eco-system.<\/a><\/strong><\/p>\n<p><strong>6) Is it possible to run Apache Spark without Hadoop?<\/strong><\/p>\n<p><strong>Ans.\u00a0\u00a0<\/strong>Yes,\u00a0Apache Spark\u00a0can run without\u00a0Hadoop, standalone, or in the cloud. Spark doesn\u2019t need a Hadoop cluster to work. It can read and then process data from other file systems as well.\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/comprehensive-hdfs-guide-introduction-architecture-data-read-write-tutorial\/\" rel=\"nofollow\">HDFS<\/a><\/strong>\u00a0is just one of the file systems that Spark supports.<\/p>\n<p>Spark does not have any storage layer, so it relies on one of the distributed storage systems for distributed computing like HDFS, Cassandra etc.<\/p>\n<p>However, there are a lot of advantages to running Spark on top of Hadoop (HDFS (for storage) +\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/yarn\/\" rel=\"nofollow\">YARN<\/a><\/strong>\u00a0(resource manager)), but it\u2019s not the mandatory requirement. It meant for distributed computing. In this case, the data distribute across the computers and Hadoop\u2019s distributed file system HDFS is used to store data that does not fit in memory.<\/p>\n<p>One more reason for using Hadoop with Spark is they both are open source and both can integrate with each other rather easily as compared to other data storage system.<\/p>\n<p><strong>For more details, please refer:\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-hadoop-compatibility\/\" rel=\"nofollow\">Apache Spark Compatibility with Hadoop<\/a><\/strong><\/p>\n<p><strong>7)\u00a0What is RDD in Apache Spark? How are they computed in Spark? what are the various ways in which it can create?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>RDD in\u00a0Apache Spark\u00a0is the representation of a set of records, it is the immutable collection of objects with distributed computing. RDD is the large collection of data or an array of reference of partitioned objects. Each and every dataset in RDD is logically partitioned across many servers so that they can compute on different nodes of the cluster.\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-fault-tolerance\/\" rel=\"nofollow\">RDDs are fault tolerant<\/a><\/strong>\u00a0i.e. self-recovered \/ recomputed in the case of failure. The dataset could data load externally by the users which can be in the form of JSON file, CSV file, text file or database via JDBC with no specific data structure.<\/p>\n<p><strong><a href=\"http:\/\/data-flair.training\/blogs\/lazy-evaluation-in-apache-spark-guide\/\" rel=\"nofollow\">RDD is Lazily Evaluated<\/a><\/strong>\u00a0i.e. it is memorized or called when required or needed, which saves lots of time. RDD is a read-only, partitioned collection of data. RDDs can creates through deterministic operations or on stable storage or from other RDDs. It can also generates by parallelizing an existing collection in your application or referring a dataset in an external storage system. It is cacheable. As it operates on data over multiple jobs in computations such as logistic regression, k-means clustering, PageRank algorithms, which makes it reuse or share data among multiple jobs.<\/p>\n<p><strong>To learn more about the RDD follow:\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD Tutorial<\/a><\/strong><\/p>\n<h2>3. Apache Spark Interview Questions For Beginners<\/h2>\n<p><strong>8)\u00a0What are the features of RDD, that makes RDD an important abstraction of Spark?<\/strong><\/p>\n<p><strong>Ans.\u00a0\u00a0<\/strong>RDD (Resilient Distributed Dataset) is a basic abstraction in\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>. Spark RDD is an immutable, partitioned collection of elements on the cluster which can operates in parallel.<\/p>\n<p><strong>Each RDD is characterized by five main properties :<\/strong><\/p>\n<p><em>Below operations are lineage operations.<\/em><\/p>\n<ul>\n<li>List or Set of partitions.<\/li>\n<li>List of dependencies on other (parent) RDD<\/li>\n<li>\u00a0A function to compute each partition<\/li>\n<\/ul>\n<p><em>Below operations are used for optimization during execution.<\/em><\/p>\n<ul>\n<li>Optional preferred location\u00a0<strong>[i.e. block location of an HDFS file] [it\u2019s about data locality]\u00a0<\/strong><\/li>\n<li>Optional partitioned info\u00a0<strong>[i.e. Hash-Partition for Key\/Value pair \u2013&gt; When data shuffled how data will\u00a0travel]<\/strong><\/li>\n<\/ul>\n<p>Examples :<\/p>\n<p><strong># HadoopRDD:\u00a0<\/strong>HadoopRDD provides core functionality for reading data stored in Hadoop (<strong><a href=\"http:\/\/data-flair.training\/blogs\/hdfs-data-read-operation\/\" rel=\"nofollow\">HDFS<\/a><\/strong>,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/hbase\/\" rel=\"nofollow\">HBase<\/a><\/strong>, Amazon S3..) using the older\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/hadoop-mapreduce-introduction-tutorial-comprehensive-guide\/\" rel=\"nofollow\">MapReduce\u00a0<\/a><\/strong>API (org.apache.hadoop.mapred)<\/p>\n<p>Properties of HadoopRDD :<\/p>\n<ol>\n<li><em>\u00a0List or Set of partitions: One per HDFS block.<\/em><\/li>\n<li><em>List of dependencies on parent RDD: None.<\/em><\/li>\n<li><em>A function to compute each partition: read respective HDFS block<\/em><\/li>\n<li><em>\u00a0Optional Preferred location: HDFS block location<\/em><\/li>\n<li><em>Optional partitioned info: None<br \/>\n<\/em><\/li>\n<\/ol>\n<p><strong>#FilteredRDD :\u00a0<\/strong>Properties of FilteredRDD:<\/p>\n<ol>\n<li><em>List or Set of partitions: No. of partitions same as parent RDD\\<\/em><\/li>\n<li><em>List of dependencies on parent RDD: \u2018one-to-one\u2019 as the parent (same as parent)<\/em><\/li>\n<li><em>A function to compute each partition: compute parent and then filter it<\/em><\/li>\n<li><em>Optional Preferred location: None (Ask Parent)<\/em><\/li>\n<li><em>Optional partitioned info: None<br \/>\n<\/em><\/li>\n<\/ol>\n<p><strong>Find features of RDD in\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-rdd-features\/\" rel=\"nofollow\">RDD Features in Spark<\/a><\/strong><\/p>\n<p><strong>9) List out the ways of creating RDD in Apache Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>There are three ways to create\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong><\/p>\n<p>(1) By Parallelizing collections in the driver program<\/p>\n<p>(2) By loading an external dataset<\/p>\n<p>(3) Creating RDD from already existing RDDs.<\/p>\n<p><strong>Create RDD By Parallelizing collections :<br \/>\n<\/strong><br \/>\nParallelized collections are created by calling\u00a0<strong>parallelize<\/strong>() method on an existing collection in driver program.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val rdd1 = Array(1,2,3,4,5)\r\nval rdd2 = sc.parallelize(rdd1)<\/pre>\n<p><strong>OR\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val myList = sc.parallelize(List(1 to 1000), 5) where 5 is the number of partitions\r\n [If we do not specify then default partition is 1<\/pre>\n<p><strong>Create by loading an external Dataset<\/strong><\/p>\n<p>In Spark, the distributed dataset can form from any data source supported by\u00a0Hadoop, including the local file system,\u00a0HDFS, Cassandra,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/hbase\/\" rel=\"nofollow\">HBase<\/a><\/strong>\u00a0etc. In this, the data is loaded from the external dataset. To create text file RDD, we can use SparkContext\u2019s textFile method. It takes URL of the file and read it as a collection of line. URL can be a local path on the machine or a hdfs:\/\/, s3n:\/\/, etc. Use SparkSession.read to access an instance of DataFrameReader. DataFrameReader supports many file formats-<\/p>\n<p><strong>i) csv (String path)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import org.apache.spark.sql.SparkSession\r\ndef main(args: Array[String]):Unit = {\r\nobject DataFormat {\r\nval spark =  SparkSession.builder.appName(\"AvgAnsTime\").master(\"local\").getOrCreate()\r\nval dataRDD = spark.read.csv(\"path\/of\/csv\/file\").rdd<\/pre>\n<p><strong>ii) json (String path)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val dataRDD = spark.read.json(\"path\/of\/json\/file\").rdd<\/pre>\n<p><strong>iii) textFile (String path)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val dataRDD = spark.read.textFile(\"path\/of\/text\/file\").rdd<\/pre>\n<p><strong>Creating RDD from existing RDD:<br \/>\n<\/strong><br \/>\n<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">Transformation<\/a><\/strong>\u00a0mutates one RDD into another RDD, thus transformation is the way to create an RDD from already existing RDD.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val words=spark.sparkContext.parallelize(Seq(\"the\", \"quick\", \"brown\", \"fox\", \"jumps\", \"over\", \"the\", \"lazy\",\r\n \"dog\"))\r\nval wordPair = words.map(w =&gt; (w.charAt(0), w))\r\nwordPair.foreach(println)<\/pre>\n<p><strong>For a detailed description on creating RDD read\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\" rel=\"nofollow\">How to create RDD in Apache Spark<\/a><\/strong><\/p>\n<p><strong>10)\u00a0Explain Transformation in RDD. How is lazy evaluation helpful in reducing the complexity of the System?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Transformations are lazy evaluated operations on RDD that create one or many new\u00a0RDDs, e.g. map, filter, reduceByKey, join, cogroup, randomSplit. Transformations are functions which take an RDD as the input and produces one or many RDDs as output. They don\u2019t change the input RDD as RDDs are immutable and hence cannot change or modify but always produces new RDD by applying the computations operations on them. By applying transformations you incrementally build an RDD lineage with all the ancestor RDDs of the final RDD(s).<\/p>\n<p><strong><a href=\"http:\/\/data-flair.training\/blogs\/lazy-evaluation-in-apache-spark-guide\/\" rel=\"nofollow\">Transformations are lazy<\/a><\/strong>, i.e. are not executed immediately. Transformations can execute only when actions are called. After executing a transformation, the result RDD(s) will always be different from their ancestors RDD and can be smaller (e.g. filter, distinct, sample), bigger (e.g. flatMap, union, cartesian) or the same size (e.g. map) or it can vary in size.<\/p>\n<p>RDD allows you to create dependencies b\/w RDDs. Dependencies are the steps for producing results in a program. Each RDD in lineage chain, string of dependencies has a function for operating its data and has a pointer dependency to its ancestor RDD. Spark will divide RDD dependencies into stages and tasks and then send those to workers for execution.<\/p>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/spark-rdd-operations-transformations-actions\/\">Follow this link to read more<\/a><\/strong><\/p>\n<p><strong>11)\u00a0What are the types of Transformation in Spark RDD Operations?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>There are two kinds of transformations:<\/p>\n<p><strong>Narrow transformations:<\/strong><\/p>\n<p>Narrow transformations are the result of map, filter and in which data to transform id from a single partition only, i.e. it is self-sustained.<br \/>\nAn output RDD has partitions with records that originate from a\u00a0single partition in the parent\u00a0<strong>RDD<\/strong>.<\/p>\n<p><strong>Wide Transformations<\/strong><\/p>\n<p>Wide transformations are the result of groupByKey and reduceByKey.\u00a0The data required to compute the records in a single partition may<br \/>\nreside in many partitions of the parent RDD.<\/p>\n<p>Wide transformations are also called shuffle transformations as they may or may not depend on a shuffle.\u00a0All of the tuples with the same key must end up in the same partition, processed by the same task.\u00a0To satisfy these operations,\u00a0<strong>Spark\u00a0<\/strong>must execute RDD shuffle, which transfers data across the cluster\u00a0and results in a new stage with a new set of partitions.<\/p>\n<p><strong>12)\u00a0What is the reason behind Transformation being a lazy operation in Apache Spark RDD? How is it useful?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Whenever a\u00a0<strong>transformation operation<\/strong>\u00a0is performed in\u00a0<strong>Apache Spark<\/strong>, it is lazily evaluated. It won\u2019t execute until an action is performed. Apache Spark just adds an entry of the transformation operation to the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\" rel=\"nofollow\">DAG (Directed Acyclic Graph)<\/a><\/strong>\u00a0of computation, which is a directed finite graph with no cycles. In this DAG, all the operations are classified into different stages, with no shuffling of data in a single stage.<\/p>\n<p>By this way, Spark can optimize the execution by looking at the DAG at its entirety, and return the appropriate result to the driver program.<\/p>\n<p>For example, consider a 1TB of a log file in HDFS containing errors, warnings, and other information. Below are the operations being performed in the driver program:<\/p>\n<ol>\n<li><strong><a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\" rel=\"nofollow\">Create an RDD<\/a><\/strong>\u00a0of this log file<\/li>\n<li>It perform a flatmap() operation on this\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>\u00a0to split the data in the log file based on tab delimiter.<\/li>\n<li>Perform a filter() operation to extract data containing only error messages<\/li>\n<li>Perform first() operation to fetch only the first error message.<\/li>\n<\/ol>\n<p>If all the transformations in the above driver program are eagerly evaluated, then the whole log file will load into memory, all of the data within the file will split base on the tab, now either it needs to write the output of FlatMap somewhere or keep it in the memory. Spark needs to wait until the next operation is performed with the resource blocked for the upcoming operation. Apart from this for each and every operation spark need to scan all the records, like for FlatMap process all the records then again process them in filter operation.<\/p>\n<p>On the other hand, if all the transformations are lazily evaluated, Spark will look at the DAG on the whole and prepare the execution plan for the application, now this plan will optimize the operation will combine\/merge into stages then the execution will start. The optimized plan created by Spark improves job\u2019s efficiency and overall throughput.<\/p>\n<p>By this lazy evaluation in Spark, the number of switches between driver program and cluster is also reduced thereby saving time and resources in memory, and also there is an increase in the speed of computation.<\/p>\n<p><strong>13)\u00a0What is RDD lineage graph? How is it useful in achieving Fault Tolerance?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The RDD Lineage Graph or RDD operator graph could be a graph of the entire parent\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDDs<\/a><\/strong>\u00a0of an RDD. It\u2019s engineered as a result of materializing\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">transformations to the RDD<\/a><\/strong>\u00a0and then creating a logical execution set up.<\/p>\n<p>The RDDs in Apache Spark rely on one or a lot of alternative RDDs. The illustration of dependencies in between RDDs is understood because of the lineage graph. Lineage graph info is employed to cypher every RDD on demand, so whenever a district of persistent RDD is lost, {the data | the info | the info} that\u2019s lost will recover using the lineage graph information.<\/p>\n<p><strong>For details on RDD DAG refer to\u00a0<\/strong><strong><a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\" rel=\"nofollow\">Directed Acyclic Graph<\/a><\/strong><\/p>\n<p><strong>14) Explain the various Transformation on Apache Spark RDD like distinct(), union(), intersection(), and subtract().<\/strong><\/p>\n<p><strong>Ans.\u00a0\u00a0distnct() transformation &#8211;<\/strong>\u00a0 If one wants only unique elements in a\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-rdd-tutorial\/\" rel=\"nofollow\">RDD<\/a><\/strong>, in that case, one can use d1.distnct() where d1 is RDD<\/p>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val d1 = sc.parallelize(List(\"c\",\"c\",\"p\",\"m\",\"t\"))\r\nval result = d1.distnct()\r\nresult.foreach{println}<\/pre>\n<p><strong>OutPut:<\/strong><br \/>\np<br \/>\nt<br \/>\nm<br \/>\nc<\/p>\n<ul>\n<li><strong>union() transformation &#8211;\u00a0<\/strong>Its simplest set operation. rdd1.union(rdd2) which outputs RDD which contains the data from both sources. If the duplicates are present in the input RDD, an output of union() transformation will contain duplicate also which can fix using distinct().<\/li>\n<\/ul>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val u1 = sc.parallelize(List(\"c\",\"c\",\"p\",\"m\",\"t\"))\r\nval u2 = sc.parallelize(List(\"c\",\"m\",\"k\"))\r\nval result = u1.union(u2)\r\nresult.foreach{println}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nc<br \/>\nc<br \/>\np<br \/>\nm<br \/>\nt<br \/>\nc<br \/>\nm<br \/>\nk<\/p>\n<ul>\n<li><strong>intersection() transformation &#8211;<\/strong> It returns the elements which are present in both the RDDs and remove all the duplicate including duplicated in single RDD<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val is1 = sc.parallelize(List(\"c\",\"c\",\"p\",\"m\",\"t\"))\r\nval is2 = sc.parallelize(List(\"c\",\"m\",\"k\"))\r\nval result = is1.union(is2)\r\nresult.foreach{println}<\/pre>\n<p><strong>Output :<\/strong><br \/>\nm<br \/>\nc<\/p>\n<ul>\n<li><strong>subtract() transformation &#8211;\u00a0<\/strong>Subtract(anotherrdd), returns an RDD that has an only value present in the first RDD and not in second RDD.<\/li>\n<\/ul>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val s1 = sc.parallelize(List(\"c\",\"c\",\"p\",\"m\",\"t\"))\r\nval s2 = sc.parallelize(List(\"c\",\"m\",\"k\"))\r\nval result = s1.subtract(s2)\r\nresult.foreach{println}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nt<br \/>\np<\/p>\n<p><strong>For more transformation in Apache Spark refer to\u00a0<\/strong><strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">Transformation and Action<\/a><\/strong><\/p>\n<p><strong>15) What is the FlatMap Transformation in Apache Spark RDD?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>FlatMap is a\u00a0<strong>transformation operation in Apache Spark\u00a0<\/strong>to\u00a0<strong>create an RDD<\/strong>\u00a0from existing\u00a0<strong>RDD<\/strong>. It takes one element from an RDD and can produce 0, 1 or many outputs based on business logic. It is similar to Map operation, but Map produces one to one output. If we perform Map operation on an RDD of length N, output RDD will also be of length N. But for FlatMap operation output RDD can be of different length based on business logic<\/p>\n<p>X\u2014\u2014A x\u2014\u2014\u2014\u2013a<br \/>\nY\u2014\u2014B y\u2014\u2014\u2014\u2013b,c<br \/>\nZ\u2014\u2014C z\u2014\u2014\u2014\u2013d,e,f<\/p>\n<p>Map Operation FlatMap Operation<\/p>\n<p>We can also say as flatMap transforms an RDD of length N into a collection of N collection, then flattens into a single RDD of results.<\/p>\n<p>If we observe the below example data1 RDD which is the output of Map operation has same no of element as of data RDD,<br \/>\nBut data2 RDD does not have the same number of elements. We can also observe here as data2 RDD is a flattened output of data1 RDD<\/p>\n<p>pranshu@pranshu-virtual-machine:~$ cat pk.txt<\/p>\n<p>1 2 3 4<\/p>\n<p>5 6 7 8 9<\/p>\n<p>10 11 12<\/p>\n<p>13 14 15 16 17<\/p>\n<p>18 19 20<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; val data = sc.textFile(\u201c\/home\/pranshu\/pk.txt\u201d)<\/pre>\n<p>17\/05\/17 07:08:20 WARN SizeEstimator: Failed to check whether UseCompressedOops is set; assuming yes<\/p>\n<p>data: org.apache.spark.rdd.RDD[String] = \/home\/pranshu\/pk.txt MapPartitionsRDD[1] at textFile at &lt;console&gt;:24<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; data.collect\r\n<\/pre>\n<p>res0: Array[String] = Array(1 2 3 4, 5 6 7 8 9, 10 11 12, 13 14 15 16 17, 18 19 20)<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt;\r\nscala&gt; val data1 = data.map(line =&gt; line.split(\u201d \u201c))<\/pre>\n<p>data1: org.apache.spark.rdd.RDD[Array[String]] = MapPartitionsRDD[2] at map at &lt;console&gt;:26<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt;\r\nscala&gt; val data2 = data.flatMap(line =&gt; line.split(\u201d \u201c))<\/pre>\n<p>data2: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[3] at flatMap at &lt;console&gt;:26<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt;\r\nscala&gt; data1.collect<\/pre>\n<p>res1: Array[Array[String]] = Array(Array(1, 2, 3, 4), Array(5, 6, 7, 8, 9), Array(10, 11, 12), Array(13, 14, 15, 16, 17), Array(18, 19, 20))<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt;\r\nscala&gt; data2.collect<\/pre>\n<p>res2: Array[String] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)<\/p>\n<p><strong>For more details, refer: <a href=\"http:\/\/data-flair.training\/blogs\/map-vs-flatmap-operation-in-apache-spark\/\">Map Vs Flatmap Operations<\/a><\/strong><\/p>\n<p><strong>16) Explain first() operation in Apache Spark RDD.<\/strong><\/p>\n<p><strong>Ans.\u00a0\u00a0<\/strong>It is an action and returns the first element of the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>.<\/p>\n<p><strong>Example<\/strong>\u00a0:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val rdd1 = sc.textFile(\"\/home\/hdadmin\/wc-data.txt\")\r\nrdd1.count\r\nrdd1.first<\/pre>\n<p><strong>Output :<\/strong><\/p>\n<p>Long: 20<\/p>\n<p>String: DataFlair is the leading technology training provider<\/p>\n<h2>4. Apache Spark Interview Questions For Intermediate<\/h2>\n<p><strong>17)\u00a0Describe join() operation. How is outer join supported?<\/strong><\/p>\n<p><strong>Ans.<\/strong> join() is transformation and is in package\u00a0org.apache.spark.rdd.pairRDDFunction<\/p>\n<p>def join[W](other: RDD[(K, W)]): RDD[(K, (V, W))]Permalink<\/p>\n<p>Return an RDD containing all pairs of elements with matching keys in this and other.<\/p>\n<p>Each pair of elements will returns as a (k, (v1, v2)) tuple, where (k, v1) is in this and (k, v2) is in other. Performs a hash join across the cluster.<\/p>\n<p>It is joining two datasets. When called on datasets of type (K, V) and (K, W), returns a dataset of (K, (V, W)) pairs with all pairs of elements for each key. Outer joins are supported through leftOuterJoin, rightOuterJoin, and fullOuterJoin.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val rdd1 = sc.parallelize(Seq((\"m\",55),(\"m\",56),(\"e\",57),(\"e\",58),(\"s\",59),(\"s\",54)))\r\nval rdd2 = sc.parallelize(Seq((\"m\",60),(\"m\",65),(\"s\",61),(\"s\",62),(\"h\",63),(\"h\",64)))\r\nval joinrdd = rdd1.join(rdd2)\r\njoinrdd.collect<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Array[(String, (Int, Int))] = Array((m,(55,60)), (m,(55,65)), (m,(56,60)), (m,(56,65)), (s,(59,61)), (s,(59,62)), (s,(54,61)), (s,(54,62)))<\/p>\n<p><strong>Example 2:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val myrdd1 = sc.parallelize(Seq((1,2),(3,4),(3,6)))\r\nval myrdd2 = sc.parallelize(Seq((3,9)))\r\nval myjoinedrdd = myrdd1.join(myrdd2)\r\nmyjoinedrdd.collect<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Array[(Int, (Int, Int))] = Array((3,(4,9)), (3,(6,9)))<\/p>\n<p><strong>18)\u00a0Describe coalesce() operation. When can you coalesce to a larger number of partitions? Explain.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>It is a\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">transformation<\/a><\/strong>\u00a0and it\u2019s in a package\u00a0<strong>org.apache.spark.rdd.ShuffledRDD<\/strong><\/p>\n<p><strong>def coalesce(numPartitions: Int, shuffle: Boolean = false, partitionCoalescer: Option[PartitionCoalescer] = Option.empty)(implicit ord: Ordering[(K, C)] = null): RDD[(K, C)]<\/strong><\/p>\n<p>Return a new\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>\u00a0that is reduced into numPartitions partitions.<\/p>\n<p>This results in a narrow dependency, e.g. if you go from 1000 partitions to 100 partitions, there will not be a shuffle, instead, each of the 100 new partitions will claim 10 of the current partitions.<\/p>\n<p>However, if you\u2019re doing a drastic coalesce, e.g. to numPartitions = 1, this may result in your computation taking place on fewer nodes than you like (e.g. one node in the case of numPartitions = 1). To avoid this, you can pass shuffle = true. This will add a shuffle step but means the current upstream partitions will execut in parallel (per whatever the current partitioning is).<\/p>\n<p>Note: With shuffle = true, you can actually coalesce to a larger number of partitions. This is useful if you have a small number of partitions, say 100, potentially with a few partitions being abnormally large. Calling coalesce(1000, shuffle = true) will result in 1000 partitions with the data distributed using a hash partitioner.<\/p>\n<p>Coalesce() operation changes a number of the partition where data is stored. It combines original partitions to a new number of partitions, so it reduces the number of partitions. Coalesce() operation is an optimized version of repartition that allows data movement, but only if you are decreasing the number of RDD partitions. It runs operations more efficiently after filtering large datasets.<\/p>\n<p><strong>Example :<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val myrdd1 = sc.parallelize(1 to 1000, 15)\r\nmyrdd1.partitions.length\r\nval myrdd2 = myrdd1.coalesce(5,false)\r\nmyrdd2.partitions.length\r\nInt = 5<\/pre>\n<p><strong>Output :<\/strong><\/p>\n<p>Int = 15<\/p>\n<p>Int = 5<\/p>\n<p><strong>19)\u00a0Explain pipe() operation. How it writes the result to the standard output?<\/strong><\/p>\n<p><strong>Ans. I<\/strong>t is a transformation.<\/p>\n<p><strong>def pipe(command: String): RDD[String]<br \/>\n<\/strong><\/p>\n<p>Return an RDD created by piping elements to a forked external process.<strong><br \/>\n<\/strong><\/p>\n<ul>\n<li>In general, Spark is using Scala, Java, and Python to write the program. However, if that is not enough, and one want to pipe (inject) the data which written in other languages like \u2018R\u2019, Spark provides the general mechanism in the form of\u00a0pipe() method.<\/li>\n<li>Spark provides the pipe() method on RDDs.<\/li>\n<li>With Spark\u2019s pipe() method, one can write a transformation of an RDD that can read each element in the RDD from standard input as String.<\/li>\n<li>It can write the results as String to the standard output.<\/li>\n<\/ul>\n<p><strong>For more transformation on RDDs see:\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">Apache Spark Operations<\/a><\/strong><\/p>\n<p><strong>20)\u00a0What is the key difference between textFile and wholeTextFile method?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Both are the method of org.apache.spark.SparkContext.<\/p>\n<p><strong>textFile() :<\/strong><\/p>\n<ul>\n<li>def textFile(path: String, minPartitions: Int = defaultMinPartitions): RDD[String]<\/li>\n<li>Read a text file from HDFS, a local file system (available on all nodes), or any Hadoop-supported file system URI, and return it as an RDD of Strings<\/li>\n<li>For example sc.textFile(\u201c\/home\/hdadmin\/wc-data.txt\u201d) so it will create RDD in which each individual line an element.<\/li>\n<li>Everyone knows the use of textFile.<\/li>\n<\/ul>\n<p><strong>wholeTextFiles() :<br \/>\n<\/strong><\/p>\n<ul>\n<li>def wholeTextFiles(path: String, minPartitions: Int = defaultMinPartitions): RDD[(String, String)]<\/li>\n<li>Read a directory of text files from HDFS, a local file system (available on all nodes), or any Hadoop-supported file system URI.<\/li>\n<li>Rather than create basic RDD, the wholeTextFile() returns pairRDD.<\/li>\n<li>For example, you have few files in a directory so by using wholeTextFile() method,<br \/>\nit creates pair RDD with a filename with a path as key,<br \/>\nand value is the whole file as a string<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">val myfilerdd = sc.wholeTextFiles(\"\/home\/hdadmin\/MyFiles\")\r\nval keyrdd = myfilerdd.keys\r\nkeyrdd.collect\r\nval filerdd = myfilerdd.values\r\nfilerdd.collect<\/pre>\n<p><strong>Output :<br \/>\n<\/strong><\/p>\n<p><strong>Array[String] = Array(<br \/>\nfile:\/home\/hdadmin\/MyFiles\/JavaSparkPi.java,<br \/>\nfile:\/home\/hdadmin\/MyFiles\/sumnumber.txt,<br \/>\nfile:\/home\/hdadmin\/MyFiles\/JavaHdfsLR.java,<br \/>\nfile:\/home\/hdadmin\/MyFiles\/JavaPageRank.java,<br \/>\nfile:\/home\/hdadmin\/MyFiles\/JavaLogQuery.java,<br \/>\nfile:\/home\/hdadmin\/MyFiles\/wc-data.txt,<br \/>\nfile:\/home\/hdadmin\/MyFiles\/nosum.txt)<\/strong><\/p>\n<p>Array[String] =<\/p>\n<p>Array(\u201c\/*<\/p>\n<ul>\n<li>Licensed to the Apache Software Foundation (ASF) under one or more<\/li>\n<li>Contributor license agreements. See the NOTICE file distributed with<\/li>\n<li>This work for additional information regarding copyright ownership.<\/li>\n<li>The ASF licenses this file to You under the Apache License, Version 2.0<\/li>\n<li>The \u201cLicense\u201d; you may not use this file except in compliance with<\/li>\n<li>The License. You may obtain a copy of the License at<\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.apache.org\/licenses\/LICENSE-2.0\" rel=\"nofollow\">http:\/\/www.apache.org\/licenses\/LICENSE-2.0<\/a><\/p>\n<ul>\n<li>Unless required by applicable law or agreed to in writing, software<\/li>\n<li>Distributed under the License is distributed on an \u201cAS IS\u201d BASIS,<\/li>\n<li>WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<\/li>\n<li>See the License for the specific language governing permissions and<\/li>\n<\/ul>\n<p><strong>21) What is Action, how it process data in Apache Spark?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong>Actions<\/strong>\u00a0return final result of\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>\u00a0computations\/operation. It triggers execution using\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\" rel=\"nofollow\">lineage graph<\/a><\/strong>\u00a0to load the data into original RDD, and carries out all intermediate transformations and returns final result to Driver program or write it out to file system.<\/p>\n<p><strong>For example:<\/strong>\u00a0First, take, reduce, collect, count, aggregate are some of the actions in spark.<\/p>\n<p>Action produces a value back to the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>\u00a0driver program. It may trigger a previously constructed,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/lazy-evaluation-in-apache-spark-guide\/\" rel=\"nofollow\">lazy RDD<\/a><\/strong>\u00a0to evaluate. It is an RDD operations that produce non-RDD values. Action function materializes a value in a Spark program. So basically an action is RDD operation that returns a value of any type but RDD[T] is an action. Actions are one of two ways to send data from executors to the driver (the other being accumulators).<\/p>\n<p>For detail study of Action refer\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">Transformation and Action in Apache Spark<\/a><\/strong>.<\/p>\n<p><strong>22)\u00a0How is Transformation on RDD different from Action?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong>Transformations\u00a0<\/strong><strong><a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\" rel=\"nofollow\">create new RDD<\/a><\/strong>\u00a0from existing\u00a0RDD<br \/>\nTransformations are executed on demand.(<strong><a href=\"http:\/\/data-flair.training\/blogs\/lazy-evaluation-in-apache-spark-guide\/\" rel=\"nofollow\">Lazy computation<\/a><\/strong>)<br \/>\nEx: filter(), union()<\/p>\n<p>An\u00a0<strong>Action<\/strong>\u00a0will return a non-RDD type (your stored value types usually)<br \/>\nActions trigger execution using\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\" rel=\"nofollow\">lineage graph<\/a><\/strong>\u00a0to load the data into original RDD<br \/>\nEx: count(), first()<\/p>\n<p><strong>23)\u00a0What are the ways in which one can know that the given operation is Transformation or Action?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>In order to identify the operation, one needs to look at the return type of an operation.<\/p>\n<ul>\n<li><strong>If the operation returns a new RDD, in that case, an operation is \u2018Transformation\u2019<\/strong><\/li>\n<li><strong>If the operation returns any other type than RDD, in that case, an operation is \u2018Action\u2019<\/strong><\/li>\n<\/ul>\n<p>Hence, Transformation constructs a new RDD from an existing one (previous one) while Action computes the result based on applied transformation and returns the result to either driver program or save it to the external storage.<\/p>\n<p><strong>Also, refer to operations of RDD in\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">Apache Spark and its Operations<\/a><\/strong><\/p>\n<p><strong>24) Describe Partition and Partitioner in Apache Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Partition in Spark is similar to split in HDFS. A partition in Spark is a logical division of data stored on a node in the cluster. They are the basic units of parallelism in Apache Spark. RDDs are a collection of partitions. When some actions are executed, a task is launched per partition.<\/p>\n<p>By default, partitions are automatically created by the framework. However, the number of partitions in Spark are configurable to suit the needs.\u00a0For the number of partitions, if spark.default.parallelism is set, then we should use the value from SparkContext defaultParallelism, othewrwise we should use the max number of upstream partitions. Unless spark.default.parallelism is set, the number of partitions will be the same as that of the largest upstream RDD, as this would least likely cause out-of-memory errors.<\/p>\n<p>A partitioner is an object that defines how the elements in a key-value pair RDD are partitioned by key, maps each key to a partition ID from 0 to numPartitions \u2013 1. It captures the data distribution at the output. With the help of partitioner, the scheduler can optimize the future operations. The contract of partitioner ensures that records for a given key have to reside on a single partition.<\/p>\n<p>We should choose a partitioner to use for a cogroup-like operations. If any of the RDDs already has a partitioner, we should choose that one. Otherwise, we use a default HashPartitioner.<\/p>\n<p>There are three types of partitioners in Spark :<\/p>\n<ul>\n<li>Hash Partitioner<\/li>\n<li>Range Partitioner<\/li>\n<li>Custom Partitioner<\/li>\n<\/ul>\n<p><strong>Hash \u2013 Partitioner:<\/strong> Hash- partitioning attempts to spread the data evenly across various partitions based on the key.<\/p>\n<p><strong>Range \u2013 Partitioner:<\/strong> In Range- Partitioning method, tuples having keys with same range will appear on the same machine.<\/p>\n<p>RDDs can create with specific partitioning in two ways :<\/p>\n<p>i) Providing explicit partitioner by calling partitionBy method on an RDD<\/p>\n<p>ii) Applying transformations that return RDDs with specific partitioners.<\/p>\n<h2>5. Apache Spark Interview Questions For Experience<\/h2>\n<p><strong>25) How can you manually partition the RDD?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>When we create the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>\u00a0from a file stored in\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/comprehensive-hdfs-guide-introduction-architecture-data-read-write-tutorial\/\" rel=\"nofollow\">HDFS<\/a><\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">data = context.textFile(\"\/user\/dataflair\/file-name\")<\/pre>\n<p>By default one partition is created for one block. ie. if we have a file of size 1280 MB (with 128 MB block size) there will be 10 HDFS blocks, hence the similar number of partitions (10) will create.<\/p>\n<p>If you want to create more partitions than the number of blocks, you can specify the same while\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\" rel=\"nofollow\">RDD creation<\/a><\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">data = context.textFile(\"\/user\/dataflair\/file-name\", 20)<\/pre>\n<p>It will create 20 partitions for the file. ie for each block 2 partitions will create.<\/p>\n<p><strong>NOTE:<\/strong>\u00a0It is often recommended to have more no of partitions than no of the block, it improves the performance<\/p>\n<p><strong>26) Name the two types of shared variable available in Apache Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>There are two types of shared variables available in\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>:<\/p>\n<ul>\n<li><strong>Accumulators<\/strong>: used to Aggregate the Information.<\/li>\n<li><strong>Broadcast variable<\/strong>: to efficiently distribute large values.<\/li>\n<\/ul>\n<p>When we pass the function to Spark, say filter(), this function can use the variable which defined outside of the function but within the Driver program but when we submit the task to Cluster, each worker node gets a new copy of variables and update from these variables not propagated back to Driver program.<\/p>\n<p>Accumulators and Broadcast variable are used to remove above drawback ( i.e. we can get the updated values back to our Driver program)<\/p>\n<p><strong>27) What are accumulators in Apache Spark?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>This discussion is in continuation with a question, Name the two types of shared variable available in Apache Spark.<\/p>\n<p><strong>Introduction of Accumulator :<\/strong><\/p>\n<ul>\n<li>An accumulator is a shared variable in\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>, used to aggregating information across the cluster.<\/li>\n<li>In other words, aggregating information\/values from worker nodes back to the driver program. ( How we will see in below session)<\/li>\n<\/ul>\n<p><strong>Why Accumulator :<\/strong><\/p>\n<ul>\n<li>When we use a function inside the operation like map(), filter() etc these functions can use the variables which defined outside these function scope in the driver program.<\/li>\n<li>When we submit the task to cluster, each task running on the cluster gets a new copy of these variables and updates from these variable do not propagate back to the driver program.<\/li>\n<li><em>Accumulator<\/em>\u00a0lowers this restriction.<\/li>\n<\/ul>\n<p><strong>Use Cases :<\/strong><\/p>\n<ul>\n<li>One of the most common uses of accumulator counts the events that occur during job execution for debugging purpose.<\/li>\n<li>Meaning count the no. of blank lines from the input file, no. of bad packets from a network during a session, during Olympic data analysis we have to find age where we said (age != \u2018NA\u2019) in SQL query in short finding bad\/corrupted records.<\/li>\n<\/ul>\n<p><strong>Examples :\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; val record = spark.read.textFile(\"\/home\/hdadmin\/wc-data-blanklines.txt\")<\/pre>\n<p>record: org.apache.spark.sql.Dataset[String] = [value: string]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; val emptylines = sc.accumulator(0) warning: there were two deprecation<\/pre>\n<p>warnings; re-run with -deprecation for details e<\/p>\n<p>mptylines: org.apache.spark.Accumulator[Int] = 0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; val processdata = record.flatMap(x =&gt;\r\n\u00a0 \u00a0 \u00a0{\r\n       if(x == \"\")\r\n       emptylines += 1\r\n       x.split(\" \")\r\n    })<\/pre>\n<p>processdata: org.apache.spark.sql.Dataset[String] = [value: string]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; processdata.collect<\/pre>\n<p>16\/12\/02 20:55:15 WARN SizeEstimator: Failed to check whether UseCompressedOops is set; assuming yes<\/p>\n<p><strong>Output :\u00a0<\/strong><\/p>\n<p>res0: Array[String] = Array(DataFlair, provides, training, on, cutting, edge, technologies., \u201c\u201d, DataFlair, is, the, leading, training, provider,, we, have, trained, 1000s, of, candidates., Training, focues, on, practical, aspects, which, industy, needs, rather, than, theoretical, knowledge., \u201c\u201d, DataFlair, helps, the, organizations, to, solve, BigData, Problems., \u201c\u201d, Javadoc, is, a, tool, for, generating, API, documentation, in, HTML, format, from, doc, comments, in, source, code., It, can, be, downloaded, only, as, part, of, the, Java, 2, SDK., To, see, documentation, generated, by, the, Javadoc, tool,, go, to, J2SE, 1.5.0, API, Documentation., \u201c\u201d, Javadoc, FAQ, -, This, FAQ, covers, where, to, download, the, Javadoc, tool,, how, to, find, a, list, of, known, bugs, and, feature, reque\u2026<\/p>\n<p>scala&gt; println(\u201cNo. of Empty Lines : \u201d + emptylines.value)<\/p>\n<p>No. of Empty Lines: 10<\/p>\n<p><strong>28) Explain SparkContext in Apache Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>A <strong><a href=\"http:\/\/data-flair.training\/blogs\/sparkcontext-in-apache-spark-tutorial\/\">SparkContext<\/a><\/strong> is a client of Spark\u2019s execution environment and it acts as the master of the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Spark\u00a0<\/a><\/strong>application. SparkContext sets up internal services and establishes a connection to a Spark execution environment. You can\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\" rel=\"nofollow\">create RDDs<\/a><\/strong>, accumulators and broadcast variables, access Spark services and run jobs (until SparkContext stops) after the creation of SparkContext. Only one SparkContext may be active per JVM. You must stop() the active SparkContext before creating a new one.<\/p>\n<p>In Spark shell, a special interpreter-aware SparkContext is already created for the user, in the variable called sc.<\/p>\n<p>The first step of any Spark driver application is to create a SparkContext. The SparkContext allows the Spark driver application to access the cluster through a resource manager. The resource manager can be\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/yarn\/\" rel=\"nofollow\">YARN<\/a><\/strong>, or\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-cluster-managers-tutorial\/\" rel=\"nofollow\">Spark\u2019s Cluster Manager<\/a><\/strong>.<\/p>\n<p><strong>Few functionalities which SparkContext offers are:\u00a0<\/strong><\/p>\n<ol>\n<li>We can get the current status of a Spark application like configuration, app name.<\/li>\n<li>We can set Configuration like master URL, default logging level.<\/li>\n<li>One can create Distributed Entities like\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDDs.<\/a><\/strong><\/li>\n<\/ol>\n<p><strong>29) Discuss the role of Spark driver in Spark application.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The spark driver is that the program that defines the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">transformations and actions on RDDs<\/a><\/strong>\u00a0of knowledge and submits a request to the master. Spark driver is a program that runs on the master node of the machine which declares transformations and actions on knowledge RDDs.<\/p>\n<p>In easy terms, the driver in Spark creates\u00a0<strong>SparkContext<\/strong>, connected to a given Spark Master. It conjointly delivers the RDD graphs to Master, wherever the standalone cluster manager runs.<\/p>\n<p><strong>Also, see\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/how-apache-spark-works-run-time-spark-architecture\/\" rel=\"nofollow\">How Spark works<\/a><\/strong><\/p>\n<p><strong>30) What role does worker node play in Apache Spark Cluster? And what is the need to register a worker node with the driver program?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>\u00a0follows a master\/slave architecture, with one master or driver process and more than one slave or worker processes<\/p>\n<ol>\n<li>The master is the driver that runs the main() program where the spark context is created. It then interacts with the cluster manager to schedule the job execution and perform the tasks.<\/li>\n<li>The worker consists of processes that can run in parallel to perform the tasks scheduled by the driver program. These processes are called executors.<\/li>\n<\/ol>\n<p>Whenever a client runs the application code, the driver programs instantiates Spark Context, converts the\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-transformations-actions-apis-apache-spark\/\" rel=\"nofollow\">transformations and actions<\/a><\/strong>\u00a0into logical<strong>\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\" rel=\"nofollow\">DAG<\/a><\/strong>\u00a0of execution. This logical DAG is then converted into a physical execution plan, which is then broken down into smaller physical execution units. The driver then interacts with the cluster manager to negotiate the resources required to perform the tasks of the application code. The cluster manager then interacts with each of the worker nodes to understand the number of executors running in each of them.<\/p>\n<p><strong>The role of worker nodes\/executors:<\/strong><\/p>\n<ol>\n<li>Perform the data processing for the application code<\/li>\n<li>Read from and write the data to the external sources<\/li>\n<li>Store the computation results in memory, or disk.<\/li>\n<\/ol>\n<p>The executors run throughout the lifetime of the Spark application. This is a static allocation of executors. The user can also decide how many numbers of executors are required to run the tasks, depending on the workload. This is a dynamic allocation of executors.<\/p>\n<p>Before the execution of tasks, the executors are registered with the driver program through the cluster manager, so that the driver knows how many numbers of executors are running to perform the scheduled tasks. The executors then start executing the tasks scheduled by the worker nodes through the cluster manager.<\/p>\n<p>Whenever any of the worker nodes fail, the tasks that are required to perform will automatically allocates to any other worker nodes<\/p>\n<p><strong>For information on how Spark works\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/how-apache-spark-works-run-time-spark-architecture\/\" rel=\"nofollow\">Spark-How it works<\/a><\/strong><\/p>\n<p><strong>31) Discuss the various running mode of Apache Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>We can launch spark application in four modes:<\/p>\n<p>1) Local Mode (local[*],local,local[2]\u2026etc)<\/p>\n<p>-&gt; When you launch spark-shell without control\/configuration argument, It will launch in local mode<\/p>\n<p>spark-shell \u2013master local[1]<\/p>\n<p>-&gt; spark-submit \u2013class com.df.SparkWordCount SparkWC.jar local[1]<\/p>\n<p>2) Spark Standalone cluster manger:<\/p>\n<p>-&gt; spark-shell \u2013master spark:\/\/hduser:7077<\/p>\n<p>-&gt; spark-submit \u2013class com.df.SparkWordCount SparkWC.jar spark:\/\/hduser:7077<\/p>\n<p>3) Yarn mode (Client\/Cluster mode):<\/p>\n<p>-&gt; spark-shell \u2013master yarn or<\/p>\n<p>(or)<\/p>\n<p>-&gt;spark-shell \u2013master yarn \u2013deploy-mode client<\/p>\n<p>Above both commands are same.<\/p>\n<p>To launch spark application in cluster mode, we have to use a spark-submit command. We cannot run yarn-cluster mode via spark-shell because when we run spark application,\u00a0driver program will be running as part application master container\/process. So it is not possible to run cluster mode via spark-shell.<\/p>\n<p>-&gt; spark-submit \u2013class com.df.SparkWordCount SparkWC.jar yarn-client<\/p>\n<p>-&gt; spark-submit \u2013class com.df.SparkWordCount SparkWC.jar yarn-cluster<\/p>\n<p>4) Mesos mode:<\/p>\n<p>-&gt; spark-shell \u2013master mesos:\/\/HOST:5050<\/p>\n<p><strong>32) Describe the run-time architecture of Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>There are 3 important components of Runtime architecture of\u00a0<a href=\"http:\/\/data-flair.training\/forums\/topic\/explain-the-run-time-architecture-of-spark\" rel=\"nofollow\">Apache Spark<\/a>\u00a0as described below.<\/p>\n<ul>\n<li>Client process<\/li>\n<li>Driver<\/li>\n<li>Executor<\/li>\n<\/ul>\n<p><strong>Responsibilities of the client process component<\/strong><\/p>\n<p>The client process starts the driver program.<\/p>\n<p>For example, the client process can be a spark-submit script for running applications, a spark-shell script, or a custom application using Spark API.\u00a0The client process prepares the classpath and all configuration options for the Spark application.<\/p>\n<p>It also passes application arguments, if any, to the application running on the driver.<\/p>\n<p><strong>Responsibilities of the driver component<\/strong><\/p>\n<p>The driver orchestrates and monitors the execution of a Spark application. There\u2019s always one driver per Spark application.<\/p>\n<p>The driver is like a wrapper around the application. The driver and its subcomponents (the Spark context and scheduler ) are responsible for:<\/p>\n<ul>\n<li>requesting memory and CPU resources from cluster managers<\/li>\n<li>breaking application logic into stages and tasks<\/li>\n<li>sending tasks to executors<\/li>\n<li>collecting the results<\/li>\n<\/ul>\n<p><strong>Responsibilities of the executors<\/strong><\/p>\n<p>The executors, which is a JVM processes, accept tasks from the driver, execute those tasks,\u00a0and return the results to the driver. Each executor has several task slots (or CPU cores) for running tasks in parallel.<\/p>\n<h2>6. Best Apache Spark Interview Questions and Answers<\/h2>\n<p><strong>33) What is the command to start and stop the Spark in an interactive shell?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Command to start the interactive shell in Scala:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt;bin\/spark-shell<\/pre>\n<p><strong>First, go the spark directory i.e.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hdadmin@ubuntu:~$ cd spark-1.6.1-bin-hadoop2.6\/\r\nhdadmin@ubuntu:~\/spark-1.6.1-bin-hadoop2.6$ bin\/spark-shell<\/pre>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br \/>\n<strong>Command to stop the interactive shell in Scala:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt;Press (Ctrl+D)<\/pre>\n<p><strong>One can see the following message<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; Stopping spark context.<\/pre>\n<p><strong>34) Describe Spark SQL.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Spark SQL is a Spark interface to work with Structured and Semi-Structured data (data that as defined fields i.e. tables). It provides abstraction layer called\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-sql-dataframe-tutorial\/\" rel=\"nofollow\">DataFrame<\/a><\/strong>\u00a0and\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-dataset-tutorial\/\" rel=\"nofollow\">DataSet<\/a><\/strong>\u00a0through with we can work with data easily. One can say that DataFrame is like a table in a relational database. Spark SQL can read and write data in a variety of Structured and Semi-Structured formats like Parquets, JSON, Hive. Using SparkSQL inside Spark application is the best way to use it. This empowers us to load data and query it with SQL. we can also combine it with \u201cregular\u201d program code in Python, Java or\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/why-you-should-learn-scala-introductory-tutorial\/\" rel=\"nofollow\">Scala<\/a><\/strong>.<\/p>\n<p>For a detailed study on SparkSQL, Refer link:\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/spark-sql-tutorial\/\" rel=\"nofollow\">Spark SQL<\/a><\/strong><\/p>\n<p><strong>35) What is SparkSession in Apache Spark? Why is it needed?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Starting from\u00a0<strong>Apache Spark<\/strong>\u00a02.0, Spark Session is the new entry point for Spark applications.<\/p>\n<p>Prior to 2.0,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/sparkcontext-in-apache-spark-tutorial\/\" rel=\"nofollow\">SparkContext<\/a><\/strong>\u00a0was the entry point for spark jobs.\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD<\/a><\/strong>\u00a0was one of the main APIs then, and it was created and manipulated using Spark Context. Every other APIs, different contexts were required \u2013 For SQL, SQL Context was required; For\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-comprehensive-guide\/\" rel=\"nofollow\">Streaming<\/a><\/strong>, Streaming Context was required; For\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/hive\/\" rel=\"nofollow\">Hive<\/a><\/strong>, Hive Context was required.<\/p>\n<p>But from 2.0, RDD along with DataSet and its subset\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-dataframe-tutorial\/\" rel=\"nofollow\">DataFrame<\/a><\/strong>\u00a0APIs are becoming the standard APIs and are a basic unit of data abstraction in Spark. All of the user-defined code will be written and evaluated against the DataSet and DataFrame APIs as well as RDD.<\/p>\n<p>So, there is a need for a new entry point build for handling these new APIs, which is why Spark Session has been introduced. Spark Session also includes all the APIs available in different contexts \u2013 Spark Context, SQL Context, Streaming Context, Hive Context.<\/p>\n<p><strong>36) Explain API create Or Replace TempView().<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>It&#8217;s basic Dataset function and under org.apache.spark.sql<\/p>\n<ul>\n<li><strong>def createOrReplaceTempView(viewName: String): Unit<\/strong><\/li>\n<li><strong>Creates a temporary view using the given name.<\/strong><\/li>\n<li><strong>The lifetime of this temporary view is tied to the SparkSession that was used to create this Dataset.<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; val df = spark.read.csv(\"\/home\/hdadmin\/titanic_data.txt\")<\/pre>\n<p>df: org.apache.spark.sql.DataFrame = [_c0: string, _c1: string &#8230; 9 more fields]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; df.printSchema<\/pre>\n<p>root<\/p>\n<p>|&#8211; _c0: string (nullable = true)<\/p>\n<p>|&#8211; _c1: string (nullable = true)<\/p>\n<p>|&#8211; _c2: string (nullable = true)<\/p>\n<p>|&#8211; _c3: string (nullable = true)<\/p>\n<p>|&#8211; _c4: string (nullable = true)<\/p>\n<p>|&#8211; _c5: string (nullable = true)<\/p>\n<p>|&#8211; _c6: string (nullable = true)<\/p>\n<p>|&#8211; _c7: string (nullable = true)<\/p>\n<p>|&#8211; _c8: string (nullable = true)<\/p>\n<p>|&#8211; _c9: string (nullable = true)<\/p>\n<p>|&#8211; _c10: string (nullable = true)<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; df.show<\/pre>\n<p>+&#8212;+&#8212;+&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8211;+&#8212;&#8212;+<\/p>\n<p>|_c0|_c1|_c2| _c3| _c4| _c5| _c6| _c7| _c8| _c9| _c10|<\/p>\n<p>+&#8212;+&#8212;+&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8211;+&#8212;&#8212;+<\/p>\n<p>| 1|1st| 1|Allen, Miss Elisa&#8230;|29.0000|Southampton| St Louis, MO| B-5| 24160 L221| 2|female|<\/p>\n<p>| 2|1st| 0|Allison, Miss Hel&#8230;| 2.0000|Southampton|Montreal, PQ \/ Ch&#8230;| C26| null| null|female|<\/p>\n<p>| 3|1st| 0|Allison, Mr Hudso&#8230;|30.0000|Southampton|Montreal, PQ \/ Ch&#8230;| C26| null|(135)| male|<\/p>\n<p>| 4|1st| 0|Allison, Mrs Huds&#8230;|25.0000|Southampton|Montreal, PQ \/ Ch&#8230;| C26| null| null|female|<\/p>\n<p>| 5|1st| 1|Allison, Master H&#8230;| 0.9167|Southampton|Montreal, PQ \/ Ch&#8230;| C22| null| 11| male|<\/p>\n<p>| 6|1st| 1| Anderson, Mr Harry|47.0000|Southampton| New York, NY| E-12| null| 3| male|<\/p>\n<p>| 7|1st| 1|Andrews, Miss Kor&#8230;|63.0000|Southampton| Hudson, NY| D-7| 13502 L77| 10|female|<\/p>\n<p>| 8|1st| 0|Andrews, Mr Thoma&#8230;|39.0000|Southampton| Belfast, NI| A-36| null| null| male|<\/p>\n<p>| 9|1st| 1|Appleton, Mrs Edw&#8230;|58.0000|Southampton| Bayside, Queens, NY| C-101| null| 2|female|<\/p>\n<p>| 10|1st| 0|Artagaveytia, Mr &#8230;|71.0000| Cherbourg| Montevideo, Uruguay| null| null| (22)| male|<\/p>\n<p>| 11|1st| 0|Astor, Colonel Jo&#8230;|47.0000| Cherbourg| New York, NY| null|17754 L224 10s 6d|(124)| male|<\/p>\n<p>| 12|1st| 1|Astor, Mrs John J&#8230;|19.0000| Cherbourg| New York, NY| null|17754 L224 10s 6d| 4|female|<\/p>\n<p>| 13|1st| 1|Aubert, Mrs Leont&#8230;| NA| Cherbourg| Paris, France| B-35| 17477 L69 6s| 9|female|<\/p>\n<p>| 14|1st| 1|Barkworth, Mr Alg&#8230;| NA|Southampton| Hessle, Yorks| A-23| null| B| male|<\/p>\n<p>| 15|1st| 0| Baumann, Mr John D.| NA|Southampton| New York, NY| null| null| null| male|<\/p>\n<p>| 16|1st| 1|Baxter, Mrs James&#8230;|50.0000| Cherbourg| Montreal, PQ|B-58\/60| null| 6|female|<\/p>\n<p>| 17|1st| 0|Baxter, Mr Quigg &#8230;|24.0000| Cherbourg| Montreal, PQ|B-58\/60| null| null| male|<\/p>\n<p>| 18|1st| 0| Beattie, Mr Thomson|36.0000| Cherbourg| Winnipeg, MN| C-6| null| null| male|<\/p>\n<p>| 19|1st| 1|Beckwith, Mr Rich&#8230;|37.0000|Southampton| New York, NY| D-35| null| 5| male|<\/p>\n<p>| 20|1st| 1|Beckwith, Mrs Ric&#8230;|47.0000|Southampton| New York, NY| D-35| null| 5|female|<\/p>\n<p>+&#8212;+&#8212;+&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8211;+&#8212;&#8212;+<\/p>\n<p>only showing top 20 rows<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scala&gt; df.createOrReplaceTempView(\"titanicdata\")<\/pre>\n<p><strong>37) What are the various advantages of DataFrame over RDD in Apache Spark?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong>DataFrames<\/strong>\u00a0are the distributed collection of data. In DataFrame, data is organized into named columns. It is conceptually similar to a table in a relational database.<br \/>\nwe can construct DataFrames from a wide array of sources. Such as structured data files, tables in Hive, external databases, or existing RDDs.<\/p>\n<p>As same as\u00a0<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-are-the-advantages-of-dataframe-in-apache-spark\" rel=\"nofollow\">RDDs<\/a><\/strong>, DataFrames are evaluated lazily(<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-are-the-advantages-of-dataframe-in-apache-spark\" rel=\"nofollow\">Lazy Evaluation<\/a><\/strong>). In other words, computation only happens when an action (e.g. display result, save output) is required.<\/p>\n<p>Out of the box, DataFrame supports reading data from the most popular formats, including JSON files, Parquet files, Hive tables. Also, can read from distributed file systems (<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-are-the-advantages-of-dataframe-in-apache-spark\" rel=\"nofollow\">HDFS<\/a><\/strong>), local file systems, cloud storage (S3), and external relational database systems through JDBC. In addition, through\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/spark-sql-tutorial\/\" rel=\"nofollow\">Spark SQL\u2019s<\/a><\/strong>\u00a0external data sources API, DataFrames can extend to support any third-party data formats or\u00a0sources. Existing third-party extensions already include Avro, CSV, ElasticSearch, and Cassandra.<\/p>\n<p>There is much more to know about DataFrames. Refer link:\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-sql-dataframe-tutorial\/\" rel=\"nofollow\">Spark SQL DataFrame<\/a><\/strong><\/p>\n<p><strong>38)\u00a0What is a DataSet? What are its advantages over DataFrame and RDD?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>In\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-for-beginners\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>, Datasets are an extension of DataFrame API. It offers object-oriented programming interface. Through Spark SQL, it takes advantage of\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/spark-sql-optimization-catalyst-optimizer\/\" rel=\"nofollow\">Spark\u2019s Catalyst optimizer<\/a><\/strong>\u00a0by exposing e data fields to a query planner.<\/p>\n<p>In\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/spark-sql-tutorial\/\" rel=\"nofollow\">SparkSQL<\/a><\/strong>, Dataset is a data structure which is strongly typed and is a map to a relational schema. Also, represents structured queries with encoders. DataSet has been released in Spark 1.6.<\/p>\n<p>In serialization and deserialization (SerDe) framework, encoder turns out as a primary concept in Spark SQL. Encoders handle all translation process between JVM objects and Spark\u2019s internal binary format. In Spark, we have built-in encoders those are very advanced. Even they generate bytecode to interact with off-heap data.<\/p>\n<p>On-demand access to individual attributes without having to de-serialize an entire object is provided by an encoder. Spark SQL uses a SerDe framework, to make input-output time and space efficient. Due to encoder knows the schema of record, it became possible to achieve serialization as well as deserialization.<\/p>\n<p>Spark Dataset is structured and lazy query expression(<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-lazy-evaluation\/\" rel=\"nofollow\">lazy Evolution<\/a><\/strong>) that triggers the action. Internally dataset represents a logical plan. The logical plan tells the computational query that we need to produce the data. the logical plan is a base catalyst query plan for the logical operator to form a logical query plan. When we analyze this and resolve we can form a physical query plan.<\/p>\n<p>As Dataset introduced after\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-rdd-tutorial\/\" rel=\"nofollow\">RDD<\/a><\/strong>\u00a0and\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-sql-dataframe-tutorial\/\" rel=\"nofollow\">DataFrame<\/a><\/strong>, it clubs the features of both. It offers the following similar features:<\/p>\n<p>1. The convenience of RDD.<br \/>\n2. Performance optimization of DataFrame.<br \/>\n3. Static type-safety of Scala.<\/p>\n<p>Hence, we have observed that Datasets provides a more functional programming interface to work with structured data.<\/p>\n<p>To know more detailed information about DataSets, refer link:\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-dataset-tutorial\/\" rel=\"nofollow\">Spark Dataset<\/a><\/strong><\/p>\n<p><strong>39) On what all basis can you differentiate RDD, DataFrame, and DataSet?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong><strong>DataFrame:\u00a0<\/strong>A Data Frame is used for storing data into tables. It is equivalent to a table in a relational database but with richer optimization. Spark DataFrame is a data abstraction and domain-specific language (DSL) applicable on a structure and semi-structured data. It is distributed the collection of data in the form of named column and row. It has a matrix-like structure whose column may be different types (numeric, logical, factor, or character ). We can say data frame has the two-dimensional array like structure where each column contains the value of one variable and row contains one set of values for each column and combines feature of list and matrices.<\/p>\n<p>For more details about DataFrame, please refer:\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-dataframe-tutorial\/\" rel=\"nofollow\">DataFrame in Spark<\/a><\/strong><\/p>\n<p><strong>RDD\u00a0<\/strong>is the representation of a set of records, immutable collection of objects with distributed computing. RDD is a large collection of data or RDD is an array of reference of partitioned objects. Each and every dataset in RDD is logically partitioned across many servers so that they can compute on different nodes of the cluster. RDDs are fault tolerant i.e. self-recovered\/recomputed in the case of failure. The dataset can load externally by the users which can be in the form of JSON file, CSV file, text file or database via JDBC with no specific data structure.<\/p>\n<p><strong>DataSet<\/strong>\u00a0in\u00a0Apache Spark, Datasets are an extension of DataFrame API. It offers object-oriented programming interface. Through Spark SQL, it takes advantage of\u00a0Spark\u2019s Catalyst optimizer\u00a0by exposing e data fields to a query planner.<\/p>\n<p>For more details about RDD, please refer:\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/rdd-in-apache-spark\/\" rel=\"nofollow\">RDD in Spark<\/a><\/strong><\/p>\n<p><strong>For the detailed comparison between RDD vs DataFrame, follow:\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-rdd-vs-dataframe-vs-dataset\/\" rel=\"nofollow\">RDD vs DataFrame vs DataSet<\/a><\/strong><\/p>\n<p><strong>40) What is Apache Spark Streaming? How is the processing of streaming data achieved in Apache Spark? Explain.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Data arriving continuously, in an unbounded sequence is a data stream. Continuously flowing input data is divided into discrete units with the help of streaming for further processing. Through Stream processing analyzing of streaming data is possible. Also, it is a low latency processing.<\/p>\n<p>In the year 2103 Spark Streaming was introduced to\u00a0Apache Spark. It is an extension of the core Spark API. Streaming offers scalable, high-throughput and\u00a0<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-is-spark-streaming\" rel=\"nofollow\">fault-tolerant<\/a><\/strong>\u00a0stream processing of live data streams. It is possible to do Data ingestion from many sources. For Example Apache Flume, Kafka, Amazon Kinesis or TCP sockets. And, By using complex algorithms that are expressed with high-level functions processing can do. For example reduce, map, join and window. Afterwards, processed data can push out to live dashboards, filesystems and databases.<\/p>\n<p>Streaming\u2019s Key abstraction is Discretized Stream. It is also known as\u00a0<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-is-spark-streaming\" rel=\"nofollow\">Spark DStream<\/a><\/strong>. A stream of data divided into small batches is represented by it. DStreams are built on Spark\u2019s core data abstraction\u201dRDDs\u201c. Streaming allows integration with any other Apache Spark components like\u00a0<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-is-spark-streaming\" rel=\"nofollow\">Spark SQL<\/a><\/strong>\u00a0and\u00a0<strong><a href=\"https:\/\/data-flair.training\/forums\/topic\/what-is-spark-streaming\" rel=\"nofollow\">Spark MLlib<\/a><\/strong>.<\/p>\n<p>To know more about Spark Streaming, follow the link:\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-streaming-tutorial\/\" rel=\"nofollow\">Spark Streaming Tutorial for Beginners<\/a><\/strong><\/p>\n<h2>7. Latest Apache Spark Interview Questions<\/h2>\n<p><strong>41) What is the abstraction of Spark Streaming?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>A\u00a0<strong>Discretized Stream (DStream)<\/strong>, the basic abstraction in\u00a0Spark Streaming, is a continuous sequence of\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-rdd-tutorial\/\" rel=\"nofollow\">RDDs<\/a><\/strong>representing a continuous stream of data. DStreams can either create from live data (such as, data from\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/hadoop-hdfs-tutorial\/\" rel=\"nofollow\">HDFS<\/a><\/strong>, Kafka or Flume) or it can generate by\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-streaming-transformation-operations\/\" rel=\"nofollow\">transformation\u00a0<\/a><\/strong>existing DStreams using operations such as map, window and reduceByKeyAndWindow.<\/p>\n<p>Internally, there are few basic properties by which DStreams is characterized:<\/p>\n<p>1. DStream depends on the list of other DStreams.<br \/>\n2. A time interval at which the DStream generates an RDD<br \/>\n3. A function that is used to generate an RDD after each time interval<\/p>\n<p>for complete introduction, refer link:\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-dstream-discretized-streams\/\" rel=\"nofollow\">Apache Spark DStream (Discretized Streams)<\/a><\/strong><\/p>\n<p><strong>42) Explain what are the various types of Transformation on DStream?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>There are two types of transformation on DStream.<\/p>\n<ul>\n<li><strong>Stateless transformation:\u00a0<\/strong>In stateless transformation, the processing of each batch does not depend on the data of its previous batches.<\/li>\n<li><strong>Stateful transformation: <\/strong>Stateful transformation use data or intermediate results from previous batches to compute the result of the current batch.<\/li>\n<\/ul>\n<p><strong>Also, refer to\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-transformation-operations\/\" rel=\"nofollow\">Transformation operation in Spark Streaming.<\/a><\/strong><\/p>\n<p><strong>43) Explain the level of parallelism in Spark Streaming. Also, describe its need.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>In order to reduce the processing time, one need to increase the parallelism. In Spark Streaming, there are three ways to increase the parallelism:<\/p>\n<ol>\n<li><strong>Increase the number of receivers :\u00a0<\/strong>If there are too many records for single receiver (single machine) to read in and distribute so that is bottleneck. So we can increase the no. of receiver depends on scenario.<\/li>\n<li><strong>Re-partition the receive data :\u00a0<\/strong>If one is not in a position to increase the no. of receivers in that case redistribute the data by re-partitioning.<\/li>\n<li><strong>Increase parallelism in aggregation :<\/strong><\/li>\n<\/ol>\n<p>for complete guide on Spark Streaming you may refer to\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-comprehensive-guide\/\" rel=\"nofollow\">Apache Spark-Streaming guide<\/a><\/p>\n<p><strong>44) Discuss writeahead logging in Apache Spark Streaming.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>There are two types of failures in any\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>\u00a0job \u2013 Either the\u00a0<strong>driver failure<\/strong>\u00a0or the\u00a0<strong>worker failure<\/strong>.<\/p>\n<p>When any worker node fails, the executor processes running in that worker node will kill, and the tasks which were scheduled on that worker node will be automatically moved to any of the other running worker nodes, and the tasks will accomplish.<\/p>\n<p>When the driver or master node fails, all of the associated worker nodes running the executors will kill, along with the data in each of the executors\u2019 memory. In the case of files being read from reliable and fault tolerant file systems like HDFS, zero data loss is always guaranteed, as the data is ready to be read anytime from the file system. Checkpointing also ensures\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-fault-tolerance\/\" rel=\"nofollow\">fault tolerance in Spark<\/a><\/strong>\u00a0by periodically saving the application data in specific intervals.<\/p>\n<p>In the case of\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-streaming-comprehensive-guide\/\" rel=\"nofollow\">Spark Streaming\u00a0<\/a><\/strong>application, zero data loss is not always guaranteed, as the data will buffer in the executors\u2019 memory until they get processed. If the driver fails, all of the executors will kill, with the data in their memory, and the data cannot recover.<\/p>\n<p>To overcome this data loss scenario,\u00a0<strong>Write Ahead Logging (WAL) has been introduced in Apache Spark 1.2.<\/strong>\u00a0With WAL enabled, the intention of the operation is first noted down in a log file, such that if the driver fails and is restarted, the noted operations in that log file can apply to the data. For sources that read streaming data, like Kafka or Flume, receivers will be receiving the data, and those will store in the executor\u2019s memory. With WAL enabled, these received data will also store in the log files.<\/p>\n<p>WAL can enable by performing the below:<\/p>\n<p>1. Setting the checkpoint directory, by using streamingContext.checkpoint(path)<\/p>\n<p>2. Enabling the WAL logging, by setting spark.stream.receiver.WriteAheadLog.enable to True.<\/p>\n<p><strong>45)\u00a0What are the roles of the file system in any framework?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>In order to manage data on computer, one has to interact with the File System directly or indirectly. When we install Hadoop on our computer, actually there are two file system exists on machine<\/p>\n<p><em>(1) Local File System\u00a0<\/em>,\u00a0<em><br \/>\n(2) HDFS (Hadoop Distributed File System)<\/em><\/p>\n<p>HDFS is sits top on of Local File System.<\/p>\n<p>Following are the genera functions of File System (be it Local or HDFS)<\/p>\n<ul>\n<li>Control the data access mechanism (i.e how data stored and retrived)<\/li>\n<li>Manages the metadata about the Files \/ Folders (i.e. created date, size etc)<\/li>\n<li>Grants the access permission and manage the securities<\/li>\n<li>Efficiently manage the storage space<\/li>\n<\/ul>\n<p><strong>For more details, please follow:\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/hadoop-hdfs-introduction-architecture-features-operations-tutorial\/\/\" rel=\"nofollow\">HDFS<\/a><\/strong><\/p>\n<p><strong>46)\u00a0What do you mean by Speculative execution in Apache Spark?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The\u00a0<strong>Speculative task<\/strong>\u00a0in\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-introduction-spark-comprehensive-tutorial\/\" rel=\"nofollow\">Apache Spark<\/a><\/strong>\u00a0is task that runs slower than the rest of the task in the job.It is health check process that verifies the task is speculated, meaning the task that runs slower than the median of successfully completed task in the task sheet. Such tasks are submitted to another worker. It runs the new copy in parallel rather than shutting down the slow task.<\/p>\n<p>In the cluster deployment mode, the thread starts as\u00a0<em>TaskSchedulerImp1<\/em><em>with\u00a0<\/em><em>spark.speculation enabled<\/em><em>. It executes periodically every\u00a0<\/em><em>spark.speculation.interval<\/em><em>\u00a0after the initial\u00a0<\/em><em>spark.speculation.interval<\/em>\u00a0passes.<\/p>\n<h2>8. Apache Spark Interview Questions for Practice<\/h2>\n<p><strong>47)\u00a0How do you parse data in XML? Which kind of class do you use with java to pass data?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>One way to parse the XML data in Java is to use the JDOM library. One can download it and import the JDOM library in your project. You can get help from Google. If still, required help post your problem in the forum. I will try to give you the solution. For Scala, Scala has the inbuilt library for XML parsing. Scala-xml_2.11-1.0.2 jar (please check them for new version if available).<\/p>\n<p><strong>48) Explain Machine Learning library in Spark.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>It is a scalable machine learning library. It delivers both blazing speed (up to 100x faster than\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/hadoop-mapreduce-tutorial\/\" rel=\"nofollow\">MapReduce<\/a><\/strong>) and high-quality algorithms (e.g., multiple iterations to increase accuracy). We can use this library in Java,\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/why-you-should-learn-scala-introductory-tutorial\/\" rel=\"nofollow\">Scala<\/a><\/strong>, and Python as part of Spark applications so that you can include it incomplete workflows. There are many tools, which are provided by MLlib. Such as-<\/p>\n<ul>\n<li><strong>ML Algorithms: <\/strong>Common learning algorithms such as classification, regression, clustering, and collaborative filtering.<\/li>\n<li><strong>Featurization: <\/strong>Feature extraction, transformation, dimensionality reduction, and selection.<\/li>\n<li><strong>Pipelines: <\/strong>Tools for constructing, evaluating, and tuning ML Pipelines.<\/li>\n<li><strong>Persistence: <\/strong>Saving and load algorithms, models, and Pipelines.<\/li>\n<li><strong>Utilities:\u00a0<\/strong>Linear algebra, statistics, data handling, etc.<\/li>\n<\/ul>\n<p>For detailed insights, follow link:\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/apache-spark-ecosystem-components\/#34_Apache_Spark_MLlib_Machine_Learning_Library\" rel=\"nofollow\">Apache Spark MLlib (Machine Learning Library)<\/a><\/strong><\/p>\n<p><strong>49) List various commonly used Machine Learning Algorithm.<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Basically, there are three types of Machine Learning Algorithms :<\/p>\n<p>(1) Supervised Learning Algorithm<\/p>\n<p>(2) Unsupervised Learning Algorithm<\/p>\n<p>(3) Reinforcement Learning Algorithm<\/p>\n<p>Most commonly used Machine Learning Algorithm is as follows :<\/p>\n<ol>\n<li>Linear Regression<\/li>\n<li>Logistic Regression<\/li>\n<li>Decision Tree<\/li>\n<li>K-Means<\/li>\n<li>KNN<\/li>\n<li>SVM<\/li>\n<li>Random Forest<\/li>\n<li>Na\u00efve Bayes<\/li>\n<li>Dimensionality Reduction Algorithm<\/li>\n<li>Gradient Boost and Adaboost<\/li>\n<\/ol>\n<p>For what is MLlib see\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-ecosystem-components\/\" rel=\"nofollow\">Apache Spark Ecosystem<\/a><\/p>\n<p><strong>50) Explain the Parquet File format in Apache Spark. When is it the best to choose this?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Parquet is the columnar information illustration that is that the best choice for storing long run massive information for analytics functions. It will perform each scan and write operations with Parquet file. It could be a columnar information storage format.<\/p>\n<p>Parquet, create to urge the benefits of compressed, economical columnar information illustration accessible to any project, despite the selection of knowledge process framework, data model, or programming language.<\/p>\n<p>Parquet could a format which will process by a variety of various systems:\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/spark-sql-tutorial\/\" rel=\"nofollow\">Spark-SQL<\/a><\/strong>, Impala,\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/category\/hive\/\" rel=\"nofollow\">Hive<\/a><\/strong>, Pig, niggard etc. It doesn\u2019t lock into a particular programming language since the format is outlined exploitation, Thrift that supports numbers of programming languages. as an example, Aepyceros melampus is written in C++ whereas Hive is written in Java however they will simply interoperate on an equivalent Parquet information.<\/p>\n<p>So, this was all on Spark Interview Questions and Answers. Hope you like the Apache spark Interview Questions and Answers.<\/p>\n<h2>3. Conclusion &#8211; Advance Apache Spark Interview Questions<\/h2>\n<p>Here we have covered all the top Apache spark interview questions which you can encounter in you spark interview. You can share the spark interview questions that you have faced in your interview and what was you experience in it. Also, for any feedback on Apache spark interview questions, feel free to comment.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2347,&quot;href&quot;:&quot;http:\\\/\\\/www.apache.org\\\/licenses\\\/LICENSE-2.0&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251206191219\\\/https:\\\/\\\/www.apache.org\\\/licenses\\\/LICENSE-2.0&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 03:58:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 08:57:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-18 03:31:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-30 05:21:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-06 19:03:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 19:00:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 04:32:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 14:56:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 17:49:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 06:55:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-23 18:13:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-31 07:37:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-11 15:40:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-18 06:42:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-30 05:27:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-12 00:05:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-15 14:25:40&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-15 14:25:40&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:2348,&quot;href&quot;:&quot;http:\\\/\\\/data-flair.training\\\/forums\\\/topic\\\/explain-the-run-time-architecture-of-spark&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20210615200933\\\/https:\\\/\\\/data-flair.training\\\/forums\\\/topic\\\/explain-the-run-time-architecture-of-spark&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 03:58:06&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2025-12-11 03:58:06&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:2349,&quot;href&quot;:&quot;https:\\\/\\\/data-flair.training\\\/forums\\\/topic\\\/what-are-the-advantages-of-dataframe-in-apache-spark&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20240618085118\\\/https:\\\/\\\/data-flair.training\\\/forums\\\/topic\\\/what-are-the-advantages-of-dataframe-in-apache-spark\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 03:58:09&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-18 03:31:54&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-01-30 05:22:04&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-06 19:05:44&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 19:01:11&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 04:32:40&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-16 15:06:37&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-22 17:49:06&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-20 06:55:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-31 07:37:43&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-11 15:40:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-18 06:42:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-30 05:27:05&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-07-12 00:05:15&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-07-15 14:25:37&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-15 14:25:37&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:2350,&quot;href&quot;:&quot;https:\\\/\\\/data-flair.training\\\/forums\\\/topic\\\/what-is-spark-streaming&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20180102235621\\\/http:\\\/\\\/data-flair.training:80\\\/forums\\\/topic\\\/what-is-spark-streaming&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 03:58:12&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-18 03:31:51&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-30 05:22:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-06 19:07:31&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 19:01:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 04:32:45&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-16 15:06:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-22 17:49:06&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-31 07:37:50&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-11 15:40:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-18 06:42:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-30 05:27:08&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-07-10 05:16:57&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-07-13 16:10:01&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-07-18 14:12:23&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-18 14:12:23&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Apache Spark Interview Questions &#8211; Objective Apache Spark is prevailing\u00a0because of its capability to handle real-time streaming and processing big data faster than Hadoop MapReduce. As the demand for Spark developers\u00a0are expected to&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":42320,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[13071,16613],"class_list":["post-2779","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spark","tag-spark-interview-questions","tag-spark-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>50 Frequently Asked Apache Spark Interview Questions - DataFlair<\/title>\n<meta name=\"description\" content=\"Apache Spark Interview questions: 50 frequently asked Questions &amp; answer for Spark developers to crack the Spark interview, tips to cracks spark interviews\" \/>\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-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"50 Frequently Asked Apache Spark Interview Questions - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Apache Spark Interview questions: 50 frequently asked Questions &amp; answer for Spark developers to crack the Spark interview, tips to cracks spark interviews\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/\" \/>\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=\"2017-06-09T06:44:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-23T11:54:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.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=\"51 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"50 Frequently Asked Apache Spark Interview Questions - DataFlair","description":"Apache Spark Interview questions: 50 frequently asked Questions & answer for Spark developers to crack the Spark interview, tips to cracks spark interviews","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-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"50 Frequently Asked Apache Spark Interview Questions - DataFlair","og_description":"Apache Spark Interview questions: 50 frequently asked Questions & answer for Spark developers to crack the Spark interview, tips to cracks spark interviews","og_url":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-06-09T06:44:09+00:00","article_modified_time":"2020-01-23T11:54:15+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.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":"51 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"50 Frequently Asked Apache Spark Interview Questions","datePublished":"2017-06-09T06:44:09+00:00","dateModified":"2020-01-23T11:54:15+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/"},"wordCount":9686,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg","keywords":["spark interview questions","Spark Interview Questions and Answers"],"articleSection":["Apache Spark Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/","url":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/","name":"50 Frequently Asked Apache Spark Interview Questions - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg","datePublished":"2017-06-09T06:44:09+00:00","dateModified":"2020-01-23T11:54:15+00:00","description":"Apache Spark Interview questions: 50 frequently asked Questions & answer for Spark developers to crack the Spark interview, tips to cracks spark interviews","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/50-frequently-asked-apacha-spark-interview-questions-2.jpg","width":1200,"height":628,"caption":"50 Frequently Asked Apache Spark Interview Questions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/apache-spark-interview-questions\/#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":"50 Frequently Asked Apache Spark Interview Questions"}]},{"@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\/2779","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=2779"}],"version-history":[{"count":16,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2779\/revisions"}],"predecessor-version":[{"id":45318,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2779\/revisions\/45318"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/42320"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=2779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=2779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=2779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}