Running Hive Queries Using Spark SQL
Running Hive Queries Using Spark SQL
Hive queries using Spark SQL. This instructional blog post explores how it can be done.
Prerequisite:
- Hadoop Cluster configured in your system
- Hive installed and configured with Hadoop
- Spark installed on the top of Hadoop eco-system
Some more configurations need to be done after the successful configuration of Hadoop, Hive, and Spark.
Open your spark-env.sh file which is present in the $SPARK_HOME/conf directory and open the spark-env.sh file. Here, add the HIVE_HOME as shown below.
1
|
export HIVE_HOME=/path_to_hive_installed_directory
|
Now copy the hive-site.xml file present in the $HIVE_HOME/conf directory to the $SPARK_HOME/conf directory.
In hive-site.xml at $SPARK_HOME/conf directory Change hive.execution engine from tez to mr
- <property>
- <name>hive.execution.engine</name>
- <value>mr</value>
- </property>
Note:
Because Spark,mr and tez these are execution engines that runs over YARN therefore when you want to run your job over spark then your engine should be spark not tez. Also a job you can only run it in single engine not on multiple engines.
Now, we will check for the tables inside Hive first. Let’s start the Hive shell first.
*Note: Make sure that the Hive Metastore service is running. Next, start it using the command hive –service metastore
In the above screenshot, you can see the list of tables present in our Hive. Here we have loaded the Olympics data. We have created queries in the first 5 rows of the Olympics table using the following command.
1
|
select * from olympics limit 5;
|
Now let us check for the same by querying from the Spark Shell.
Now, start the Spark Shell and import the Hive context. Create one variable for the HiveContext as follows:
12
3
|
import org.apache.spark.sql.hive.HiveContext
val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
import hiveContext._
|
You can see the same in the following screen shot.
Now let us see the list of tables present in Hive from the Spark Shell. Use the following command to view the list.
Now let us query on the olympics table from the Spark Shell.
1
|
val first_5_rows = hiveContext.sql("select * from olympics limit 5").foreach(println)
|
In the above screen shot, you can see the first 5 rows of the dataset. Like this, we can execute any kind of queries on Hive data using the Spark-SQL engine.
Let us now create one table in spark shell and let us see whether will it get reflected in the hive or not.
Following is the way you can create a table in Hive through Spark Shell.
1
|
val create_table = hiveContext.sql("create table spark_olympic(athelete STRING,age INT,country STRING,year STRING,closing STRING,sport STRING,gold INT,silver INT,bronze INT,total INT) row format delimited fields terminated by '\t' stored as textfile")
|
We have created a table with the name spark_olympic but we haven’t loaded any data into this table.
Let us see whether it will get reflected in the Hive shell or not.
In the above screenshot, you can see the table spark_olympic is in the Hive Shell and there is no data in it.
Now, let us load the data from the Spark Shell into this table and query the data from Hive.
This is how we can load data into a Hive table from a Spark Shell.
1
|
val load_data = hiveContext.sql("load data local inpath '/home/kiran/Desktop/olympix_data.csv' into table spark_olympic")
|
Now let us query the data in the Hive Shell from Spark.
We can run all the Hive queries on the Hive tables using the Spark SQL engine.
thanks for the worth able informations and keep update the latest informations about hadoop.
ReplyDeleteBig data training institute in chennai
Best hadoop training in chennai
Best institute for big data in chennai
Big data classes in chennai
I went through your blog and I must say that you have done a great job in explaining all aspects of digital marketing clearly. Would highly appreciate if you could spare some time and take a look at my page.
ReplyDeleteHadoop Training In Navalur
java training in navalur
I really wanna to thank you for giving a wonderful opportunity to read this blog.kindly update more and more like this in future.
ReplyDeleteHadoop Training in Chennai
Big data training in chennai
hadoop training in velachery
java training in chennai
python training in chennai
selenium training in chennai
Hadoop training in chennai
Big data training in chennai
big data training in velachery
Thank you for sharing such great information very useful to us.
ReplyDeleteBig Data Training in Gurgaon
Your explanation way is too good and I like your nice post. You are providing the information was very useful for me and also I learn huge details from your blog.
ReplyDeleteLinux Training in Chennai
Linux Course in Chennai
Pega Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Tableau Training in Chennai
Unix Training in Chennai
Embedded System Course Chennai
Linux Training Fees in Chennai
Good job! Fruitful article. I like this very much. It is very useful for my research. It shows your interest in this topic very well. I hope you will post some more information about the software. Please keep sharing!!
ReplyDeleteHadoop Training in Chennai
Big Data Training in Chennai
Devops Training in Chennai
Digital Marketing Course in Chennai
RPA Training in Chennai
SEO Training in Chennai
Hadoop Training in Tambaram
Hadoop Training in Porur
Great post and more informative!keep sharing this!
ReplyDeleteIonic Training in Chennai
Ionic framework training
Xamarin Course in Chennai
Node JS Course in Chennai
Big Data Analytics Training in Chennai
Hadoop Admin Training in Chennai
Informatica MDM Training in Chennai
This comment has been removed by the author.
ReplyDeleteI feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
ReplyDeleteRegards,
Blue Prism Training in Chennai
UiPath Training in Chennai
Machine Learning course in Chennai
Blue Prism Training in Anna Nagar
Blue Prism Training in T Nagar
Blue Prism Training in Velachery
Blue Prism Training in Tambaram
thanks for sharing .
ReplyDeletehttp://splashs.in/
Apache Spark Training in Chennai, Pallikaranai
DeleteYou shared a very useful post.,
ReplyDeleteMachine Learning training in Pallikranai Chennai
Pytorch training in Pallikaranai chennai
Data science training in Pallikaranai
Python Training in Pallikaranai chennai
Deep learning with Pytorch training in Pallikaranai chennai
Bigdata training in Pallikaranai chennai
Mongodb Nosql training in Pallikaranai chennai
Spark with ML training in Pallikaranai chennai
Data science Python training in Pallikaranai
Bigdata Spark training in Pallikaranai chennai
The Blog is really very Impressive. every concepts are neatly represented.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
Thank you - Just shared this post with a colleague who would benefit from reading this, really enjoyed it. Read more about big data hadoop online training from our website.
ReplyDeleteThank you for info..
ReplyDeleteReally this blog looks awesome,keep sharing more blog posts with us.
big data online training
It's Really A Great Post. interesting and very useful links. Thanks for sharing. oracle training in chennai
ReplyDeleteThanks.. Nice post..
ReplyDeleteMachine Learning training in Pallikranai Chennai
Data science training in Pallikaranai
Python Training in Pallikaranai chennai
Bigdata training in Pallikaranai chennai
Spark with ML training in Pallikaranai chennai
MMORPG OYUNLARI
ReplyDeleteInstagram Takipci Satın Al
Tiktok Jeton Hilesi
Tiktok jeton hilesi
antalya saç ekimi
Instagram Takipci
instagram takipçi satın al
metin2 pvp serverlar
instagram takipçi satın al
smm panel
ReplyDeletesmm panel
is ilanlari blog
İnstagram takipçi satın al
Hırdavatçı
BEYAZESYATEKNİKSERVİSİ.COM.TR
Servis
Jeton hilesi indir
pendik toshiba klima servisi
ReplyDeletetuzla lg klima servisi
tuzla alarko carrier klima servisi
tuzla daikin klima servisi
çekmeköy toshiba klima servisi
ataşehir toshiba klima servisi
çekmeköy beko klima servisi
ataşehir beko klima servisi
maltepe lg klima servisi