{"id":1754,"date":"2019-05-24T05:16:46","date_gmt":"2019-05-24T05:16:46","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=1754"},"modified":"2025-06-13T06:27:10","modified_gmt":"2025-06-13T06:27:10","slug":"apache-spark-sql-commands","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/","title":{"rendered":"Apache Spark SQL Commands"},"content":{"rendered":"<h1 style=\"text-align: center;\"><strong>Apache Spark SQL Commands<\/strong><\/h1>\n<p>&nbsp;<\/p>\n<p><strong>Apache Spark SQL Commands<\/strong>, welcome to the world of Apache Spark Basic SQL commands. Are you the one who is looking forward to knowing the Apache Spark SQL commands List which comes under <a href=\"https:\/\/prwatech.in\/apache-spark-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apache Spark<\/a>? Or the one who is very keen to explore the list of all the SQL commands in Apache Spark with examples that are available? Then you\u2019ve landed on the Right path which provides the standard and Basic Apache Spark SQL 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\/blog\/tableau\/tooltips-in-tableau\/\" 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 SQL Commands which Every Spark Developer should know about. So follow the Below Mentioned Apache Spark Basic SQL Commands 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<p><strong>Spark context(sc) :<\/strong> To initialize the functionalities of Spark SQL<\/p>\n<p>To create a spark context<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1755\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png\" alt=\"Apache Spark SQL Commands\" width=\"850\" height=\"83\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png 623w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7-300x29.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Check the context created<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1756\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/2-7.png\" alt=\"spark sql tutorial\" width=\"850\" height=\"46\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/2-7.png 627w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/2-7-300x16.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><strong>Data set:<\/strong> Optimized version of RDD which uses interpreter and optimizer for processing.<\/p>\n<p><strong>Data Frame:<\/strong> A data frame is a Data set organized into named columns. It is conceptually equivalent to a table in a relational database or a data frame in R\/Python.<\/p>\n<h2><strong>Data Frame<\/strong><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1757\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/3-7.png\" alt=\"spark sql tutorial pdf\" width=\"850\" height=\"62\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/3-7.png 626w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/3-7-300x22.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1758\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/4-7.png\" alt=\"spark sql query examples\" width=\"850\" height=\"53\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/4-7.png 624w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/4-7-300x19.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1759\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/5-7.png\" alt=\"Apache spar sql data frame\" width=\"850\" height=\"54\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/5-7.png 626w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/5-7-300x19.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1760\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/6-7.png\" alt=\"scala readvalue\" width=\"850\" height=\"487\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/6-7.png 600w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/6-7-300x172.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Schema of a table:<\/strong> Using the below-mentioned command we find out the schema of Data set<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1761\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/7-7.png\" alt=\"readvalue,printschema\" width=\"850\" height=\"146\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/7-7.png 625w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/7-7-300x51.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Show data:<\/strong> Using below-mentioned command we display the values inside our data set<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1762\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/8-7.png\" alt=\"readvalue show\" width=\"850\" height=\"29\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/8-7.png 591w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/8-7-300x10.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1763\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/9-6.png\" alt=\"course name\" width=\"850\" height=\"269\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/9-6.png 609w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/9-6-300x95.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Reading files using spark session:<\/strong> Using the below-mentioned command we can read data from an external source by providing their path of existence.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1764\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/10-6.png\" alt=\"spark.read.json\" width=\"850\" height=\"110\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/10-6.png 618w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/10-6-300x39.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Show value:<\/strong> To Display the data<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1765\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/11-6.png\" alt=\"scala df show\" width=\"850\" height=\"359\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/11-6.png 580w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/11-6-300x127.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Selecting a particular column:<\/strong> Using below-mentioned command we can display all the data from a particular column<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1766\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/12-4.png\" alt=\"df select name show\" width=\"850\" height=\"333\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/12-4.png 544w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/12-4-300x117.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Selecting more than one column:<\/strong> Using below-mentioned command we can display all the data from two selected column<\/h3>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1767\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/13-4.png\" alt=\"scala df select name age show\" width=\"850\" height=\"288\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/13-4.png 628w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/13-4-300x102.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<h3><strong>Incrementing the value of column: <\/strong>Using below-mentioned command we can increment the data with the given value<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1768\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/14-3.png\" alt=\"spark select age name \" width=\"850\" height=\"311\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/14-3.png 593w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/14-3-300x110.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Alias:<\/strong> Using the below-mentioned command we can display columns as other names.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1769\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/15-3.png\" alt=\"scala df show name alias name age alias age alias ageplusten\" width=\"850\" height=\"302\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/15-3.png 621w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/15-3-300x107.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Filter:<\/strong> Using below-mentioned command we can filter out the value from using different parameters<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1770\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/16-3.png\" alt=\"scala df filter age show\" width=\"850\" height=\"271\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/16-3.png 543w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/16-3-300x96.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>Data frames are also transformational in nature and they are immutable<\/p>\n<h2><strong>Group by<\/strong><\/h2>\n<h3><strong>Various Functions in Group By<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1771\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/17-3.png\" alt=\" scala df groupby course\" width=\"850\" height=\"104\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/17-3.png 582w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/17-3-300x37.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Count:<\/strong> Using this Group by function to count the given data set.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1772\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/18-2.png\" alt=\"df groupby course count\" width=\"850\" height=\"87\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/18-2.png 619w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/18-2-300x31.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1773\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/19-2.png\" alt=\"scala res22 show\" width=\"850\" height=\"338\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/19-2.png 614w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/19-2-300x119.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Max:<\/strong> Using this Group by function to find out the maximum values for given datasets.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1774\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/20-2.png\" alt=\"apache spark sql data frame\" width=\"850\" height=\"414\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/20-2.png 622w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/20-2-300x146.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Min:<\/strong> Using this Group by function to find out the minimum values for given datasets.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1775\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/21-2.png\" alt=\"course min age\" width=\"850\" height=\"645\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/21-2.png 625w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/21-2-300x228.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Average:<\/strong> Using this Group by function to find out the average values for given datasets.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1776\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/22-1.png\" alt=\"course avg age\" width=\"850\" height=\"317\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/22-1.png 624w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/22-1-300x112.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Write:<\/strong> Using the below-mentioned command we can write and store data on the mentioned location as per user requirement.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1777\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/23-1.png\" alt=\"de write json\" width=\"850\" height=\"58\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/23-1.png 613w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/23-1-300x21.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1778\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/24-1.png\" alt=\"course age name\" width=\"850\" height=\"288\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/24-1.png 622w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/24-1-300x102.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>To perform query we create a template view<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1779\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/25-1.png\" alt=\"val student data json spark read json\" width=\"850\" height=\"179\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/25-1.png 622w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/25-1-300x63.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1780\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/26-1.png\" alt=\"spark sql\" width=\"850\" height=\"452\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/26-1.png 623w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/26-1-300x159.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><strong>Now we can use command per operations using SQL queries\u00a0<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1781\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/27-1.png\" alt=\"val new data spark sql\" width=\"850\" height=\"245\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/27-1.png 624w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/27-1-300x87.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h2><strong>Data Set<\/strong><\/h2>\n<p><strong>Create dataset:<\/strong> Dataset is only created using (seq) object<\/p>\n<h3><strong>Data set with metadata info<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1782\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/28-1.png\" alt=\"class player\" width=\"850\" height=\"271\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/28-1.png 620w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/28-1-300x96.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1783\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/29-1.png\" alt=\"caseipl tods\" width=\"850\" height=\"83\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/29-1.png 628w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/29-1-300x29.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1784\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/30-1.png\" alt=\"scala res40 show\" width=\"850\" height=\"269\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/30-1.png 622w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/30-1-300x95.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1785\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/31-1.png\" alt=\" SQL Commands\" width=\"850\" height=\"38\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/31-1.png 621w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/31-1-300x14.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Now we can perform SQL query<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1786\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/32-1.png\" alt=\"spark sql from IPL\" width=\"850\" height=\"271\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/32-1.png 621w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/32-1-300x96.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>UDF Functions<\/strong><\/h3>\n<p>UDF allows us to register custom functions to call within SQL. These are a very popular way to expose advanced functionality to SQL users in an organization so that these users can call into it without writing code<\/p>\n<h3><strong>Test Case 1: <\/strong>Converting Celsius into Fahrenheit<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1787\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/33-1.png\" alt=\"val temperature \" width=\"850\" height=\"109\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/33-1.png 623w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/33-1-300x39.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1788\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/34-1.png\" alt=\"temperature show\" width=\"850\" height=\"286\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/34-1.png 573w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/34-1-300x101.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><\/h3>\n<h3><strong>Register UDF:<\/strong> Using the below-mentioned command we are registering new functions as per user need.<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1789\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/35-1.png\" alt=\"spark udf register\" width=\"850\" height=\"141\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/35-1.png 625w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/35-1-300x50.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1790\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/36-1.png\" alt=\"temperture creater or replace\" width=\"850\" height=\"60\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/36-1.png 625w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/36-1-300x21.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1791\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/37-1.png\" alt=\"spark sql\" width=\"850\" height=\"115\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/37-1.png 622w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/37-1-300x41.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1792\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/38-1.png\" alt=\"res65 show\" width=\"850\" height=\"263\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/38-1.png 620w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/38-1-300x93.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Test case 2:<\/strong> Lower to Upper case<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1793\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/39-1.png\" alt=\"val dataset\" width=\"850\" height=\"59\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/39-1.png 624w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/39-1-300x21.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1794\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/40-1.png\" alt=\"val upper\" width=\"850\" height=\"70\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/40-1.png 570w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/40-1-300x25.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1795\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/41.png\" alt=\"import org apache spark sql\" width=\"850\" height=\"56\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/41.png 627w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/41-300x20.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1796\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/42.png\" alt=\"val upper udf\" width=\"850\" height=\"75\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/42.png 624w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/42-300x26.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1797\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/43.png\" alt=\"data set with columm\" width=\"850\" height=\"181\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/43.png 624w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/43-300x64.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache Spark SQL Commands &nbsp; Apache Spark SQL Commands, welcome to the world of Apache Spark Basic SQL commands. Are you the one who is looking forward to knowing the Apache Spark SQL commands List which comes under Apache Spark? Or the one who is very keen to explore the list of all the SQL [&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,1691],"tags":[295,882,886,881,887,884,885,883,880],"class_list":["post-1754","post","type-post","status-publish","format-standard","hentry","category-apache-spark","category-apache-spark-sql","tag-apache-spark-sql-commands","tag-queries-in-scala","tag-scala-functions","tag-scala-queries","tag-scala-query","tag-scala-sql-query","tag-scala-table-creation","tag-spark-scala-dataset","tag-spark-sql-commands"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apache Spark SQL Commands | Basic SQL Commands for Apache Spark<\/title>\n<meta name=\"description\" content=\"Here is the list of Apache Spark SQL Commands which are available, Get the best Basic SQL Commands for Apache Spark 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=\"Apache Spark SQL Commands | Basic SQL Commands for Apache Spark\" \/>\n<meta property=\"og:description\" content=\"Here is the list of Apache Spark SQL Commands which are available, Get the best Basic SQL Commands for Apache Spark from Prwatech\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/\" \/>\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-05-24T05:16:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-13T06:27:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.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=\"12 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-sql\/apache-spark-sql-commands\/\",\"url\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/\",\"name\":\"Apache Spark SQL Commands | Basic SQL Commands for Apache Spark\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png\",\"datePublished\":\"2019-05-24T05:16:46+00:00\",\"dateModified\":\"2025-06-13T06:27:10+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Here is the list of Apache Spark SQL Commands which are available, Get the best Basic SQL Commands for Apache Spark from Prwatech\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png\",\"width\":623,\"height\":61},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apache Spark SQL Commands\"}]},{\"@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":"Apache Spark SQL Commands | Basic SQL Commands for Apache Spark","description":"Here is the list of Apache Spark SQL Commands which are available, Get the best Basic SQL Commands for Apache Spark 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":"Apache Spark SQL Commands | Basic SQL Commands for Apache Spark","og_description":"Here is the list of Apache Spark SQL Commands which are available, Get the best Basic SQL Commands for Apache Spark from Prwatech","og_url":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2019-05-24T05:16:46+00:00","article_modified_time":"2025-06-13T06:27:10+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.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":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/","url":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/","name":"Apache Spark SQL Commands | Basic SQL Commands for Apache Spark","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png","datePublished":"2019-05-24T05:16:46+00:00","dateModified":"2025-06-13T06:27:10+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Here is the list of Apache Spark SQL Commands which are available, Get the best Basic SQL Commands for Apache Spark from Prwatech","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/05\/1-7.png","width":623,"height":61},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/apache-spark\/apache-spark-sql\/apache-spark-sql-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Apache Spark SQL Commands"}]},{"@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\/1754","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=1754"}],"version-history":[{"count":15,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/1754\/revisions"}],"predecessor-version":[{"id":11621,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/1754\/revisions\/11621"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=1754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=1754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=1754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}