

{"id":2202,"date":"2017-04-24T08:52:48","date_gmt":"2017-04-24T08:52:48","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=2202"},"modified":"2018-11-21T11:39:01","modified_gmt":"2018-11-21T06:09:01","slug":"learn-apache-spark-sparkcontext","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/","title":{"rendered":"Learn SparkContext &#8211; Introduction and Functions"},"content":{"rendered":"<h2>1. Objective<\/h2>\n<p><strong>SparkContext<\/strong>\u00a0is the entry gate of\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-tutorial-quickstart-introduction\/\">Apache Spark<\/a><\/strong>\u00a0functionality. The most important step of any Spark driver application is to generate SparkContext. It allows your Spark Application to access Spark Cluster with the help of Resource Manager (<strong>YARN\/Mesos<\/strong>). To create SparkContext, first\u00a0<strong>SparkConf<\/strong>\u00a0should be made. The SparkConf has a configuration parameter that our\u00a0Spark\u00a0driver application will pass to SparkContext.<br \/>\nIn this Apache Spark tutorial, we will deeply understand what is SparkContext in Spark. How to create SparkContext Class in Spark with the help of Spark-Scala word count program. We will also learn various tasks of SparkContext and how to stop SparkContext in Apache Spark.<\/p>\n<p>So, let&#8217;s start SparkContext tutorial.<\/p>\n<div id=\"attachment_43071\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-43071\" class=\"size-full wp-image-43071\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg\" alt=\"Learn SparkContext - Introduction and Functions\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-43071\" class=\"wp-caption-text\">Learn SparkContext &#8211; Introduction and Functions<\/p><\/div>\n<p>Learn\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-installation-in-standalone-mode\/\">how to install Apache Spark in standalone mode<\/a>\u00a0and\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-installation-on-multi-node-cluster-step-by-step-guide\/\">Apache Spark installation in a\u00a0<\/a><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-installation-on-multi-node-cluster-step-by-step-guide\/\">multi-node cluster.<\/a><\/strong><\/p>\n<h2>2. What is SparkContext in Apache Spark?<\/h2>\n<p>SparkContext is the entry point of Spark functionality. The most important step of any Spark driver application is to generate SparkContext. It allows your Spark Application to access Spark Cluster with the help of Resource Manager. The resource manager can be one of these three-\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-cluster-managers-tutorial\/\">Spark Standalone<\/a><\/strong>, \u00a0<a href=\"http:\/\/data-flair.training\/blogs\/hadoop-yarn-tutorial\/\"><strong>YARN<\/strong><\/a>, <a href=\"http:\/\/data-flair.training\/blogs\/apache-mesos-tutorial-learn-mesos\/\"><strong>Apache Mesos<\/strong>.<\/a><\/p>\n<h2>3. How to Create SparkContext Class?<\/h2>\n<p>If you want to create SparkContext, first\u00a0<strong>SparkConf<\/strong>\u00a0should be made. The SparkConf has a configuration parameter that our Spark driver application will pass to SparkContext. Some of these parameter defines properties of Spark driver application. While some are used by Spark to allocate resources on the cluster, like the number, memory size, and cores used by executor running on the worker nodes.<br \/>\nIn short, it guides how to access the Spark cluster. After the creation of a SparkContext object, we can invoke functions such as\u00a0<strong>textFile, sequenceFile, parallelize<\/strong>\u00a0etc. The different contexts in which it can run are local, yarn-client, Mesos URL and Spark URL.<br \/>\nOnce the SparkContext is created, it can be used to\u00a0<strong><a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\">create RDDs<\/a><\/strong>, broadcast variable, and accumulator, ingress Spark service and run jobs. All these things can be carried out until SparkContext is stopped.<\/p>\n<h2>4. Stopping SparkContext<\/h2>\n<p>Only one SparkContext may be active per JVM. You must stop the active it before creating a new one as below:<br \/>\nstop(): Unit<br \/>\nIt will display the following message:<br \/>\n<strong><em>INFO SparkContext: Successfully stopped SparkContext<\/em><\/strong><\/p>\n<h2>5. Spark Scala Word Count Example<\/h2>\n<p>Let&#8217;s see how to create SparkContext using SparkConf with the help of Spark-Scala word count example-<br \/>\n[php]<br \/>\npackage com.dataflair.spark<br \/>\nimport org.apache.spark.SparkContext<br \/>\nimport org.apache.spark.SparkConf<br \/>\nobject Wordcount {<br \/>\ndef main(args: Array[String]) {<br \/>\n\/\/Create conf object<br \/>\nval conf = new SparkConf()<br \/>\n.setAppName(&#8220;WordCount&#8221;)<br \/>\n\/\/create spark context object<br \/>\nval sc = new SparkContext(conf)<br \/>\n\/\/Check whether sufficient params are supplied<br \/>\nif (args.length &lt; 2) {<br \/>\nprintln(&#8220;Usage: ScalaWordCount &lt;input&gt; &lt;output&gt;&#8221;)<br \/>\nSystem.exit(1)<br \/>\n}<br \/>\n\/\/Read file and create RDD<br \/>\nval rawData = sc.textFile(args(0))<br \/>\n\/\/convert the lines into words using flatMap operation<br \/>\nval words = rawData.flatMap(line =&gt; line.split(&#8221; &#8220;))<br \/>\n\/\/count the individual words using map and reduceByKey operation<br \/>\nval wordCount = words.map(word =&gt; (word, 1)).reduceByKey(_ + _)<br \/>\n\/\/Save the result<br \/>\nwordCount.saveAsTextFile(args(1))<br \/>\n\/\/stop the spark context<br \/>\nsc.stop<br \/>\n}<br \/>\n}[\/php]<\/p>\n<h2>6. Functions of SparkContext in Apache Spark<\/h2>\n<div id=\"attachment_3819\" style=\"width: 812px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/functions-of-sparkcontext-in-apache-spark.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3819\" class=\"wp-image-3819 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/functions-of-sparkcontext-in-apache-spark.jpg\" alt=\"10 Important Functions of SparkContext in Apache Spark\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/functions-of-sparkcontext-in-apache-spark.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/functions-of-sparkcontext-in-apache-spark-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/functions-of-sparkcontext-in-apache-spark-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/functions-of-sparkcontext-in-apache-spark-768x402.jpg 768w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><p id=\"caption-attachment-3819\" class=\"wp-caption-text\">10 Important Functions of SparkContext in Apache Spark<\/p><\/div>\n<h3>i. To get the current status of Spark Application<\/h3>\n<ul>\n<li><strong>SpkEnv &#8211;\u00a0<\/strong>It is a runtime environment with Spark\u2019s public services. It interacts with each other to establish a distributed computing platform for Spark Application. A SparkEnv object that holds the required runtime services for<strong>\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/how-apache-spark-works-run-time-spark-architecture\/\">running Spark application<\/a><\/strong>\u00a0with the different\u00a0environment for the driver and executor represents the Spark runtime environment.<\/li>\n<li><strong>SparkConf &#8211;\u00a0<\/strong>The Spark Properties handles maximum applications settings and are configured separately for each application. We can also easily set these properties on a SparkConf. Some common properties like master URL and application name, as well as an arbitrary\u00a0key-value pair, configured through the<strong> set()<\/strong> method.<\/li>\n<li><strong>Deployment environment (as master URL) &#8211;\u00a0<\/strong>Spark deployment environment are of two types namely local and clustered.\u00a0<strong>Local mode<\/strong>\u00a0is non-distributed single-JVM deployment mode. All the execution components &#8211; driver, executor,\u00a0LocalSchedulerBackend, and master are present in same single JVM. Hence, the only mode where drivers are useful for execution is the local mode. For testing, debugging or demonstration purpose, the local mode is suitable because it requires no earlier setup to launch spark application. While in clustered mode, the Spark runs in distributive mode. <strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-cluster-managers-tutorial\/\">Learn Spark Cluster Manager in detail.<\/a><\/strong><\/li>\n<\/ul>\n<h3>ii. To set the configuration<\/h3>\n<ul>\n<li><strong>Master URL &#8211;\u00a0<\/strong>The master method returns back the current value of <em>spark.master<\/em> which is deployment environment in use.<\/li>\n<li><strong>Local properties-Creating Logical Job Groups &#8211;\u00a0<\/strong>The reason of local properties concept is to form logical groups of jobs by means of properties that\u00a0create\u00a0the separate job launched from different threads belong to a single logic group.<strong>\u00a0<\/strong>We can set a local property which will affect Spark jobs submitted from a thread, such as the Spark fair scheduler pool.<\/li>\n<li><strong>Default Logging level &#8211;\u00a0<\/strong>It lets you set the root login level in a Spark application, for example,\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-shell-commands-beginners-tutorial\/\">Spark Shell.<\/a><\/li>\n<\/ul>\n<h3>iii. To Access various services<\/h3>\n<p>It also helps in accessing services like <em>TaskScheduler, LiveListenBus, BlockManager, SchedulerBackend, ShuffelManager<\/em> and the optional <em>ContextCleaner<\/em>.<\/p>\n<h3>iv. To Cancel a job<\/h3>\n<p><em>cancleJob<\/em>\u00a0simply requests <em>DAGScheduler<\/em> to drop a Spark job.<br \/>\nLearn about Spark\u00a0<a href=\"http:\/\/data-flair.training\/blogs\/directed-acyclic-graph-dag-in-apache-spark\/\"><strong>DAG(Directed Acyclic Graph)<\/strong><\/a>\u00a0in detail.<\/p>\n<h3>v. To Cancel a stage<\/h3>\n<p>cancleStage\u00a0simply requests <em>DAGScheduler<\/em> to drop a Spark stage.<\/p>\n<h3>vi. For Closure cleaning in Spark<\/h3>\n<p>Spark\u00a0cleanups the closure every time an Action occurs, i.e. the body of Action before it is serialized and sent over the wire to execute. The clean method in SparkContext does this. This, in turn, calls <em>ClosureClean.clean<\/em> method. It not only cleans the closure but also referenced closure is clean transitively. It assumes serializable until it does not explicitly reference unserializable objects.<\/p>\n<h3>vii. To Register Spark listener<\/h3>\n<p>We can register a custom\u00a0<em>SparkListenerInterface<\/em>\u00a0with the help of\u00a0<em>addSparkListener<\/em>\u00a0method. We can also register custom listeners using the\u00a0<em>spark.extraListeners<\/em>\u00a0setting.<\/p>\n<h3>viii. Programmable Dynamic allocation<\/h3>\n<p>It also provides the following method as the developer API for dynamic allocation of executors: <em>requestExecutors,\u00a0killExecutors, requestTotalExecutors,\u00a0getExecutorIds<\/em>.<\/p>\n<h3>ix. To access persistent RDD<\/h3>\n<p><em>getPersistentRDDs<\/em><strong>\u00a0<\/strong>gives the collection of <strong>RDDs<\/strong> that have marked themselves as persistent via cache.<\/p>\n<h3>x. To unpersist RDDs<\/h3>\n<p>From the master\u2019s Block Manager and the internal\u00a0<em>persistentRdds\u00a0<\/em>mapping, the unpersist removes the RDD.<\/p>\n<p>So, this was all in Sparkcontext Tutorial. Hope you like our explanation.<\/p>\n<h2>7. Conclusion<\/h2>\n<p>Hence, SparkContext provides the various functions in Spark like get the current status of Spark Application, set the configuration,\u00a0cancel\u00a0a job, Cancel a stage and much more. It is an entry point to the Spark functionality. Thus, it acts a backbone.<br \/>\nIf you have any query about this tutorial, So feel free to Share with us. We will be glad to solve them.<br \/>\n<strong>See Also-<\/strong><\/p>\n<ul>\n<li><strong><a href=\"http:\/\/data-flair.training\/blogs\/how-to-create-rdds-in-apache-spark\/\">Ways To Create RDD in Spark<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/data-flair.training\/blogs\/apache-spark-hadoop-compatibility\/\">Apache Spark Compatibility with Hadoop<\/a><\/strong><\/li>\n<\/ul>\n<p><strong><a href=\"https:\/\/spark.apache.org\/docs\/2.3.0\/\">Reference for Spark<\/a><\/strong><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2359,&quot;href&quot;:&quot;https:\\\/\\\/spark.apache.org\\\/docs\\\/2.3.0&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250905123917\\\/https:\\\/\\\/spark.apache.org\\\/docs\\\/2.3.0\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 04:18:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-14 14:28:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-17 19:55:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-21 05:47:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-24 05:53:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-27 11:04:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-30 17:18:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-02 18:43:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-06 02:01:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 07:10:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 20:30:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-16 05:06:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-19 07:59:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-22 09:39:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-25 15:25:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-29 05:12:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-02 05:12:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-05 08:43:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-08 19:58:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-11 21:35:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 18:46:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 11:58:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-23 01:53:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-26 08:15:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 11:04:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 19:03:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 01:21:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 04:00:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 06:21:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 16:11:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-23 13:45:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 13:10:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 19:02:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 09:30:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-07 13:45:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 15:34:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 07:09:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 07:20:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 19:08:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-24 18:20:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-28 10:19:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-02 09:09:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-05 21:34:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-09 08:44:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-12 17:54:45&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-05-17 09:22:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-21 21:30:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-25 02:23:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-30 05:07:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 11:39:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-05 22:12:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-11 09:37:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-15 07:21:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-18 19:31:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-23 04:46:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-26 13:06:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-29 21:26:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-03 16:04:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-07 14:35:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-11 03:23:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-14 09:21:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-17 21:45:55&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-17 21:45:55&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Objective SparkContext\u00a0is the entry gate of\u00a0Apache Spark\u00a0functionality. The most important step of any Spark driver application is to generate SparkContext. It allows your Spark Application to access Spark Cluster with the help of&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":43071,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[6721,13156,13159,13160,13162],"class_list":["post-2202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spark","tag-initiallizing-sparkcontext","tag-sparkcontext-class","tag-sparkcontext-functions","tag-sparkcontext-in-apache-spark","tag-sparkcontext-in-spark"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learn SparkContext - Introduction and Functions - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what is SparkContext in Spark,initiallizing SparkContext,SparkContext functions, SparkEnv, SparkConf,Stop SparkContext,Spark-scala word count program\" \/>\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\/learn-apache-spark-sparkcontext\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn SparkContext - Introduction and Functions - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what is SparkContext in Spark,initiallizing SparkContext,SparkContext functions, SparkEnv, SparkConf,Stop SparkContext,Spark-scala word count program\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/\" \/>\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-04-24T08:52:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-21T06:09:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.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=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn SparkContext - Introduction and Functions - DataFlair","description":"Learn what is SparkContext in Spark,initiallizing SparkContext,SparkContext functions, SparkEnv, SparkConf,Stop SparkContext,Spark-scala word count program","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\/learn-apache-spark-sparkcontext\/","og_locale":"en_US","og_type":"article","og_title":"Learn SparkContext - Introduction and Functions - DataFlair","og_description":"Learn what is SparkContext in Spark,initiallizing SparkContext,SparkContext functions, SparkEnv, SparkConf,Stop SparkContext,Spark-scala word count program","og_url":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-04-24T08:52:48+00:00","article_modified_time":"2018-11-21T06:09:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Learn SparkContext &#8211; Introduction and Functions","datePublished":"2017-04-24T08:52:48+00:00","dateModified":"2018-11-21T06:09:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/"},"wordCount":1161,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg","keywords":["initiallizing SparkContext","SparkContext Class","SparkContext Functions","SparkContext in Apache Spark","SparkContext in Spark"],"articleSection":["Apache Spark Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/","url":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/","name":"Learn SparkContext - Introduction and Functions - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg","datePublished":"2017-04-24T08:52:48+00:00","dateModified":"2018-11-21T06:09:01+00:00","description":"Learn what is SparkContext in Spark,initiallizing SparkContext,SparkContext functions, SparkEnv, SparkConf,Stop SparkContext,Spark-scala word count program","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/04\/SparkContext-Apache-Spark-768x402-1.jpg","width":1200,"height":628,"caption":"Learn SparkContext - Introduction and Functions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/learn-apache-spark-sparkcontext\/#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":"Learn SparkContext &#8211; Introduction and Functions"}]},{"@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\/2202","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=2202"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2202\/revisions"}],"predecessor-version":[{"id":43072,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2202\/revisions\/43072"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/43071"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=2202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=2202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=2202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}