{"id":1315,"date":"2019-04-04T12:11:18","date_gmt":"2019-04-04T12:11:18","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=1315"},"modified":"2024-04-03T07:30:36","modified_gmt":"2024-04-03T07:30:36","slug":"scala-commands-for-spark","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/","title":{"rendered":"Scala commands for Spark"},"content":{"rendered":"<h1 style=\"text-align: center;\">Scala commands for Spark<\/h1>\n<p>&nbsp;<\/p>\n<p><strong>the Scala commands for Spark<\/strong>, welcome to the world of Apache Spark Basic Scala Commands. Are you the one who is looking forward to knowing the scala commands for spark List which are useful for <a href=\"https:\/\/prwatech.in\/apache-spark-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Spark developers<\/a>? Or the one who is very keen to explore the list of all the basic scala commands in Apache Spark with examples that are available? Then you\u2019ve landed on the Right path which provides the standard and <a href=\"https:\/\/prwatech.in\/apache-spark-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apache Spark<\/a> Basic scala Commands.<\/p>\n<p>If you are the one who is keen to learn the technology then learn the advanced certification course from the best <a href=\"https:\/\/prwatech.in\/apache-spark-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apache Spark training institute<\/a> who can help guide you about the course from the 0 Level to Advanced level. So don\u2019t just dream to become the certified Pro Developer achieve it by choosing the best World classes <a href=\"https:\/\/prwatech.in\/apache-spark-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apache Spark training institute in Bangalore<\/a> which consists of World-class Trainers.<\/p>\n<p>We, <a href=\"http:\/\/prwatech.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prwatech<\/a> listed some of the top Apache Spark basic Scala Commands which Every Spark Developer should know about. So follow the Below Mentioned scala commands for spark and Learn the Advanced <a href=\"https:\/\/prwatech.in\/apache-spark-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apache Spark course<\/a> from the best Spark Trainer like a Pro.<\/p>\n<h2>Apache Spark Basic Scala Commands<\/h2>\n<h3><strong>Expressions are computable statements<\/strong><\/h3>\n<p>scala&gt; 12 * 10<\/p>\n<p>res0: Int = 120<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1316\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png\" alt=\"Scala commands for Spark\" width=\"850\" height=\"128\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png 666w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1-300x45.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p>You can output results of expressions using\u00a0println<\/p>\n<p>Or (what You want to print you can print using <em>println<\/em>)<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1317\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/2.png\" alt=\"scala print\" width=\"850\" height=\"119\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/2.png 664w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/2-300x42.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p><strong>Ex:-<\/strong>println(\u201cHello Prwatech\u201d)<\/p>\n<p>scala&gt; println(&#8220;Hello,&#8221; + &#8220;Prwatech&#8221;)<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1318\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/3.png\" alt=\"scala print in\" width=\"850\" height=\"158\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/3.png 674w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/3-300x56.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>Values<\/strong><\/h3>\n<p>You can name the results of expressions with the\u00a0value keyword.<\/p>\n<p>Here such as\u00a0 \u2018x\u2019 is value \u201cReferencing a value doesn\u2019t re-compute it\u201d<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1319\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/4.png\" alt=\"values\" width=\"850\" height=\"167\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/4.png 672w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/4-300x59.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>\u00a0Variable<\/strong><\/h3>\n<p>Variables are like values, except you can re-assign them. You can define a variable with the\u00a0var\u00a0keyword.<\/p>\n<p>varx=6 + 4<\/p>\n<p>x=10<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1320\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/5.png\" alt=\"Variable\" width=\"850\" height=\"111\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/5.png 674w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/5-300x39.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>uBlocks<\/strong><\/h3>\n<p>You can combine expressions by surrounding them with\u00a0{}. We call this a block.<\/p>\n<p>The result of the last expression in the block is the result of the overall block too.<\/p>\n<p><strong> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1321\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/6.png\" alt=\"spark tutorial\" width=\"850\" height=\"134\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/6.png 671w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/6-300x47.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1322\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/7-1.png\" alt=\"apache spark\" width=\"850\" height=\"139\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/7-1.png 666w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/7-1-300x49.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>Functions<\/strong><\/h3>\n<p>Functions are expressions that take parameters.<\/p>\n<p>You can define an anonymous function (i.e. no name) that returns a given integer plus two<\/p>\n<p>On the left of\u00a0=,&gt;\u00a0is a list of parameters. On the right is an expression involving the parameters.<\/p>\n<p>You can also name functions.<\/p>\n<p><strong> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1323\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/8.png\" alt=\"function of command\" width=\"850\" height=\"234\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/8.png 673w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/8-300x82.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1324\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/9.png\" alt=\"spark tutorial \" width=\"850\" height=\"271\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/9.png 667w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/9-300x96.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p>Functions may take multiple parameters.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1325\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/10.png\" alt=\"spark sql\" width=\"850\" height=\"125\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/10.png 665w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/10-300x44.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p>Or it can take no parameters.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1326\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/11.png\" alt=\"spark dataframe\" width=\"850\" height=\"141\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/11.png 644w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/11-300x50.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>Methods<\/strong><\/h3>\n<p>The Methods look and behave very similar to functions, but there are a few key differences between them<\/p>\n<p>Methods are defined with the\u00a0def\u00a0keyword.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1327\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/12.png\" alt=\"Methods are defined with the\u00a0def\u00a0keyword\" width=\"850\" height=\"144\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/12.png 661w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/12-300x51.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p>Notice how the return type is declared\u00a0after\u00a0the parameter list and a colon: Int.<\/p>\n<p>Methods can take multiple parameter lists.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1328\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/13.png\" alt=\"Methods can take multiple parameter lists\" width=\"850\" height=\"158\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/13.png 672w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/13-300x56.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>Classes<\/strong><\/h3>\n<p>You can define classes with the class keyword followed by its name and constructor parameters.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1329\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/14.png\" alt=\"class prwatech\" width=\"850\" height=\"172\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/14.png 658w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/14-300x61.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>Objects<\/strong><\/h3>\n<p>Objects are single instances of their own definitions. You can think of them as singletons of their own classes.<\/p>\n<p>You can define objects with the\u00a0object\u00a0keyword.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1330\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/15.png\" alt=\"You can define objects with the\u00a0object\u00a0keyword.\" width=\"850\" height=\"482\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/15.png 663w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/15-300x170.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<h3><strong>SINGLETON OBJECT<\/strong><\/h3>\n<p>Scala classes do not have a static keyword, so they have Singleton Object.<\/p>\n<p>The constructor of the singleton object is executed when the object is first used.<\/p>\n<p>An object has all the features of the class.<\/p>\n<p>The parameters cannot be provided to the constructor.<\/p>\n<p>They can be imported from anywhere in the program.<\/p>\n<p>Singleton Objects are used in the following cases:<\/p>\n<p>When a singleton instance is required for co-ordinating a service.<\/p>\n<p>#When a single immutable instance could be shared for efficiency purposes.<\/p>\n<p>When an immutable instance is required for utility functions or constants.<\/p>\n<p><strong><u><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1331\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/16.png\" alt=\"utility functions or constants.\" width=\"850\" height=\"408\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/16.png 618w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/16-300x144.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/u><\/strong><\/p>\n<h3><strong>\u00a0If else Condition<\/strong><\/h3>\n<p>Command:-var a\u00a0 = 8<\/p>\n<p>val s = if ( a&gt;1 &amp;&amp;a&lt;9)1else 0<\/p>\n<p>Command:-var a\u00a0 = 9<\/p>\n<p>val s = if ( a&gt;1 &amp;&amp; a&lt;9)1else 0<\/p>\n<p><strong><em>\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1363\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/1-24.png\" alt=\"commands var a\" width=\"850\" height=\"384\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/1-24.png 677w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/1-24-300x136.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/em><\/strong><\/p>\n<p><strong><em>\u00a0<\/em><\/strong><\/p>\n<h3><strong>While Loop<\/strong><\/h3>\n<p><em>Command:-<\/em><em>var args = \u201cPRWATECH\u201d<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var i = 0<\/em><\/p>\n<p><em>\u00a0 while (i&lt;args.length)<\/em><\/p>\n<p><em>\u00a0{<\/em><\/p>\n<p><em>println(args(i))<\/em><\/p>\n<p><em>i +=1<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/em><\/p>\n<p><strong><em>\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1364\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/2-23.png\" alt=\"Command:-var args\" width=\"850\" height=\"473\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/2-23.png 677w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/2-23-300x167.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/em><\/strong><\/p>\n<p><strong><em>\u00a0<\/em><\/strong><\/p>\n<h3><strong>Foreach Loop<\/strong><\/h3>\n<p><em>Command:-<\/em><em>var args = \u201cSCALA\u201d<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 args.foreach(println)<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1365\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/3-24.png\" alt=\"Command:-var args scala\" width=\"850\" height=\"281\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/3-24.png 680w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/3-24-300x99.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>For Loop<\/strong><\/h3>\n<p><em>Command:-<\/em><em>for(i&lt;1 to 5)<\/em><\/p>\n<p><em>print(i)<\/em><\/p>\n<p><em>Command:-<\/em><em> for(i&lt;11 to 25)<\/em><\/p>\n<p><em>print(i)<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1366\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/4-19.png\" alt=\"commands for scala\" width=\"850\" height=\"251\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/4-19.png 677w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/4-19-300x89.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Nested for loop<\/strong><\/h3>\n<p><em>Command:-<\/em><em>for (i&lt;-1 to 5; j =i) println(20*i+j)<\/em><\/p>\n<p><u><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1367\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/5-19.png\" alt=\"Scala commands \" width=\"850\" height=\"209\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/5-19.png 675w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/5-19-300x74.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/u><\/p>\n<h3><strong>How to write a function<\/strong><\/h3>\n<p><em>First define the function and then call it with the value<\/em><\/p>\n<p><strong><em>Command:-<\/em><\/strong><em>def area(radius:Int):Double= {7.20*radius*radius}<\/em><\/p>\n<p><strong><u><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1368\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/6-20.png\" alt=\"Command:-def area\" width=\"850\" height=\"132\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/6-20.png 675w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/6-20-300x47.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/u><\/strong><\/p>\n<h3><strong>Argument to function<\/strong><\/h3>\n<p><em>Command:-<\/em><em>def concatstr(arg1:String,arg2:String = \u201cInstitute\u201d,arg3:String = \u201cPrwatech\u201d) = println(arg1 + arg2 +arg3)<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0 <\/em><em>concatstr(\u201cBigData\u201d)<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; concatstr(\u201cBigData\u201d, arg3=\u201dspark\u201d)<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211; concatstr(\u201cBigData\u201d)<\/em><\/p>\n<p><em>\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1369\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/7-18.png\" alt=\"Command:-def concatstr\" width=\"850\" height=\"310\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/7-18.png 682w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/7-18-300x110.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/em><em>\u00a0<\/em><em>\u00a0<\/em><\/p>\n<h3><strong>Scala Procedure<\/strong><\/h3>\n<p><em>Scala has a special function that doesn\u2019t return any value.<\/em><\/p>\n<p><em>If there is a scala function without a preceding \u201c=\u201d symbol, then\u00a0 the return type of the function is <\/em><em>unit<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0 <\/em><em>Such a function is called procedures<\/em><em>.<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0 <\/em><em>Procedures don\u2019t return any value in scala<\/em><\/p>\n<p><em>Commands:-def rect_area(length:Float, breadth:Float) {val area = length*breadth; println(area)}<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1370\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/8-14.png\" alt=\"Scala Procedure\" width=\"850\" height=\"223\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/8-14.png 680w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/8-14-300x79.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>\u00a0Scala<\/strong><\/h3>\n<p><strong>Collection<\/strong><\/p>\n<p><em>Scala has a rich library of collection, they are:-<\/em><\/p>\n<p><em>Array<\/em><\/p>\n<p><em>ArrayBuffers<\/em><\/p>\n<p><em>Maps<\/em><\/p>\n<p><em>Tuples<\/em><\/p>\n<p><em>Lists<\/em><\/p>\n<p><em>\u00a0<\/em><\/p>\n<h3><strong>Array<\/strong><\/h3>\n<p><em>It is the collection of elements or records of same type<\/em><\/p>\n<p><strong><em>Command:-<\/em><\/strong><em>var i = Array(\u201cHello\u201d, \u201cPrwatech\u201d)<\/em><\/p>\n<p><em>\u00a0print(i(0))<\/em><\/p>\n<p><em>\u00a0print(i(1))<\/em><\/p>\n<p><em>\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1371\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/9-12.png\" alt=\"scala var i\" width=\"850\" height=\"195\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/9-12.png 679w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/03\/9-12-300x69.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/em><\/p>\n<h3><strong>Array Buffers<\/strong><\/h3>\n<p>Commands for initializing ArrayBuffers<strong>: <\/strong><em>import scala.collection.mutable.ArrayBuffer<\/em><\/p>\n<p><em>\u00a0<\/em><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><em>\u00a0<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scala commands for Spark &nbsp; the Scala commands for Spark, welcome to the world of Apache Spark Basic Scala Commands. Are you the one who is looking forward to knowing the scala commands for spark List which are useful for Spark developers? Or the one who is very keen to explore the list of all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,1693],"tags":[299,868,869,865,866,864,298,867],"class_list":["post-1315","post","type-post","status-publish","format-standard","hentry","category-apache-spark","category-apache-spark-scala","tag-apache-spark-basic-scala-commands","tag-apache-spark-scala","tag-basic-scala-commands","tag-commands-scala","tag-scala-command-in-spark","tag-scala-commands","tag-scala-commands-for-spark","tag-spark-scala-commands"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scala Commands for Spark | Apache Spark Basic Scala Commands<\/title>\n<meta name=\"description\" content=\"Here is the list of Scala Commands for Spark which are available, Get the best Apache Spark Basic Scala Commands from Prwatech\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Commands for Spark | Apache Spark Basic Scala Commands\" \/>\n<meta property=\"og:description\" content=\"Here is the list of Scala Commands for Spark which are available, Get the best Apache Spark Basic Scala Commands from Prwatech\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-04T12:11:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-03T07:30:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/\",\"url\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/\",\"name\":\"Scala Commands for Spark | Apache Spark Basic Scala Commands\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png\",\"datePublished\":\"2019-04-04T12:11:18+00:00\",\"dateModified\":\"2024-04-03T07:30:36+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Here is the list of Scala Commands for Spark which are available, Get the best Apache Spark Basic Scala Commands from Prwatech\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png\",\"width\":666,\"height\":100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala commands for Spark\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Commands for Spark | Apache Spark Basic Scala Commands","description":"Here is the list of Scala Commands for Spark which are available, Get the best Apache Spark Basic Scala Commands from Prwatech","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Scala Commands for Spark | Apache Spark Basic Scala Commands","og_description":"Here is the list of Scala Commands for Spark which are available, Get the best Apache Spark Basic Scala Commands from Prwatech","og_url":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2019-04-04T12:11:18+00:00","article_modified_time":"2024-04-03T07:30:36+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png","type":"","width":"","height":""}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/","url":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/","name":"Scala Commands for Spark | Apache Spark Basic Scala Commands","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png","datePublished":"2019-04-04T12:11:18+00:00","dateModified":"2024-04-03T07:30:36+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Here is the list of Scala Commands for Spark which are available, Get the best Apache Spark Basic Scala Commands from Prwatech","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/04\/1.png","width":666,"height":100},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-scala\/scala-commands-for-spark\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala commands for Spark"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/1315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=1315"}],"version-history":[{"count":13,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/1315\/revisions"}],"predecessor-version":[{"id":11234,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/1315\/revisions\/11234"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=1315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=1315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=1315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}