Microsoft Azure Data Engineering Certificatio ...
- 13k Enrolled Learners
- Weekend
- Live Class
In this blog post, let’s discuss top Hive commands with examples. These Hive commands are very important to set up the foundation for Hive Certification Training.
Apache Hive is a Data warehouse system which is built to work on Hadoop. It is used to querying and managing large datasets residing in distributed storage. Before becoming an open source project of Apache Hadoop, Hive was originated in Facebook. It provides a mechanism to project structure onto the data in Hadoop and to query that data using a SQL-like language called HiveQL (HQL).
Hive is used because the tables in Hive are similar to tables in a relational database. If you are familiar with SQL, it’s a cakewalk. Many users can simultaneously query the data using Hive-QL.
Hive defines a simple SQL-like query language to querying and managing large datasets called Hive-QL ( HQL ). It’s easy to use if you’re familiar with SQL Language. Hive allows programmers who are familiar with the language to write the custom MapReduce framework to perform more sophisticated analysis.
You can even check out the details of Big Data with the Azure Data Engineering Certification in Bangalore.
1. The Apache Hive distributed storage.
2. Hive provides tools to enable easy data extract/transform/load (ETL)
3. It provides the structure on a variety of data formats.
4. By using Hive, we can access files stored in Hadoop Distributed File System (HDFS is used to querying and managing large datasets residing in) or in other data storage systems such as Apache HBase.
• Hive is not designed for Online transaction processing (OLTP ), it is only used for the Online Analytical Processing.
• Hive supports overwriting or apprehending data, but not updates and deletes.
• In Hive, sub queries are not supported.
The following are the reasons why Hive is used in spite of Pig’s availability:
Metastore :
Hive stores the schema of the Hive tables in a Hive Metastore. Metastore is used to hold all the information about the tables and partitions that are in the warehouse. By default, the metastore is run in the same process as the Hive service and the default Metastore is DerBy Database.
SerDe :
Serializer, Deserializer gives instructions to hive on how to process a record.
Data Definition Language (DDL )
DDL statements are used to build and modify the tables and other objects in the database.
DDL Command | Function |
CREATE | It is used to create a table or Database |
SHOW | It is used to show Database, Table, Properties, etc |
ALTER | It is used to make changes to the existing table |
DESCRIBE | It describes the table columns |
TRUNCATE | Used to permanently truncate and delete the rows of table |
DELETE | Deletes the table data, but, can be restored |
Go to Hive shell by giving the command sudo hive and enter the command ‘create database<data base name>’ to create the new database in the Hive.
To list out the databases in Hive warehouse, enter the command ‘show databases’.
The database creates in a default location of the Hive warehouse. In Cloudera, Hive database store in a /user/hive/warehouse.
The command to use the database is USE <data base name>
Copy the input data to HDFS from local by using the copy From Local command.
When we create a table in hive, it creates in the default location of the hive warehouse. – “/user/hive/warehouse”, after creation of the table we can move the data from HDFS to hive table.
The following command creates a table with in location of “/user/hive/warehouse/retail.db”
Note : retail.db is the database created in the Hive warehouse.
Describe provides information about the schema of the table.
Data Manipulation Language (DML )
DML statements are used to retrieve, store, modify, delete, insert and update data in the database.
Example :
LOAD, INSERT Statements.
Syntax :
LOAD data <LOCAL> inpath <file path> into table [tablename]
The Load operation is used to move the data into corresponding Hive table. If the keyword local is specified, then in the load command will give the local file system path. If the keyword local is not specified we have to use the HDFS path of the file.
Here are some examples for the LOAD data LOCAL command
After loading the data into the Hive table we can apply the Data Manipulation Statements or aggregate functions retrieve the data.
Example to count number of records:
Count aggregate function is used count the total number of the records in a table.
‘create external’ Table :
The create external keyword is used to create a table and provides a location where the table will create, so that Hive does not use a default location for this table. An EXTERNAL table points to any HDFS location for its storage, rather than default storage.
Insert Command:
The insert command is used to load the data Hive table. Inserts can be done to a table or a partition.
• INSERT OVERWRITE is used to overwrite the existing data in the table or partition.
• INSERT INTO is used to append the data into existing data in a table. (Note: INSERT INTO syntax is work from the version 0.8)
‘Partitioned by‘ is used to divided the table into the Partition and can be divided in to buckets by using the ‘Clustered By‘ command.
When we insert the data Hive throwing errors, the dynamic partition mode is strict and dynamic partition not enabled. So we need to set the following parameters in Hive shell.
set hive.exec.dynamic.partition=true;
To enable dynamic partitions, by default, it’s false
set hive.exec.dynamic.partition.mode=nonstrict;
Partition is done by the category and can be divided in to buckets by using the ‘Clustered By’ command.
The ‘Drop Table’ statement deletes the data and metadata for a table. In the case of external tables, only the metadata is deleted.
The ‘Drop Table’ statement deletes the data and metadata for a table. In the case of external tables, only the metadata is deleted.
Load data local inpath ‘aru.txt’ into table tablename and then we check employee1 table by using Select * from table name command
To count the number of records in table by using Select count(*) from txnrecords;
Select count (DISTINCT category) from tablename;
This command will count the different category of ‘cate’ table. Here there are 3 different categories.
Suppose there is another table cate where f1 is field name of category.
Group command is used to group the result-set by one or more columns.
Select category, sum( amount) from txt records group by category
It calculates the amount of same category.
The result one table is stored in to another table.
Create table newtablename as select * from oldtablename;
Here one more table is created in the name ‘mailid’
A Join operation is performed to combining fields from two tables by using values common to each.
The result of a left outer join (or simply left join) for tables A and B always contains all records of the “left” table (A), even if the join-condition does not find any matching record in the “right” table (B).
A right outer join (or right join) closely resembles a left outer join, except with the treatment of the tables reversed. Every row from the “right” table (B) will appear in the joined table at least once.
The joined table will contain all records from both tables, and fill in NULLs for missing matches on either side.
Once done with hive we can use quit command to exit from the hive shell.
Hive is just a part of the big puzzle called Big Data and Hadoop. Hadoop is much more than just Hive. Click below to see what other skills you should master in Hadoop. You can even check out the details of Big Data with the Data Engineering Courses.
Got a question for us? Please mention it in the comments section and we will get back to you.
Related Posts:
7 Ways Big Data Training Can Change Your Organization
edureka.co
nice blog with great explanation sir can you provide me any sample project of hive
Hey jeet, thanks for checking out our tutorial.
We might be able to share something on the lines of this use case. Please share your email address and we will send it. Cheers!
jeetmwd@gmail.com
Can you send me as well to my mail id: akash.detani.exp@gmail.com
could you please send it to me as well: gmadhan31@gmail.com
Could you please send me the details to my email id also: araju.testing@gmail.com
Very Nice blog, Can you please take one sample real time project in Hadoop and explain flow and architecture.
Plz mail to patildhanashri165@gmail.com
Hey Dhanashri, thanks for checking out our blog.
You will find hands-on tutorials in this Hadoop playlist: on our YouTube channel: https://www.youtube.com/watch?list=PL9ooVrP1hQOEmUPq5vhWfLYJH_b9jFBbR&v=zez2Tv-bcXY.
If you would like to avail practical training with real-time projects, you can can enroll into our Hadoop course here: https://www.edureka.co/big-data-hadoop-training-certification.
Hope this helps. Cheers!
Very nice Blog…
Can you please send me some sample real time project on Hadoop to
dembanivishal@gmail.com
Hey Vishal, thanks for checking out our blog. We’re glad you liked it.
You will find hands-on tutorials in this Hadoop playlist: https://www.youtube.com/playlist?list=PL9ooVrP1hQOEmUPq5vhWfLYJH_b9jFBbR.
If you would like to avail practical training with real-time projects, you can can enroll into our Hadoop course here: https://www.edureka.co/big-data-hadoop-training-certification. We have also emailed a sample set.
Hope this helps. Cheers!
Awesome blog… Can you please help me with some one sample realtime project in hadoop.
Hey Peeyush, thanks for checking out our blog. Could you please share your email address. Cheers!
Hi
Email address is sharmapeeyush3@gmail.com
Can you please help me with some one sample realtime project in hadoop. Email address is sumachowdarym95@gmail.com
Very helpful blog.. Can you please take one sample realtime project in hadoop and explain flow and architecture.
Hey Purni, thanks for checking out our blog. Please share your contact email address with us and we will get in touch. Cheers!
purni_04@yahoomail.com
Hi, we have sent some information to you. Cheers!
Very Nice blog, Can you please take one sample realtime project in hadoop and explain flow and architecture.
plz mail to mailstomyspace@gmail.com
+myspace, thanks for checking out our blog. We’re glad you liked it.
We have sent it. Cheers!
Sir, I want to know how insurance company use big data to improve their customer experience using an example. if possible then plz explain flow diagram. like how many layer should be there which file should be used
Hey Rajiv, thanks for checking out our blog. Here are a couple of related blogs that you can refer to for the explanation:
https://www.edureka.co/blog/videos/improving-customer-service-with-big-data/
https://www.edureka.co/blog/game-changing-big-data-use-cases/
Please feel free to write to us if you have any questions. Hope this helps. Cheers!
very helpful blog..nice content..easy to understand ..Sir i want to know that is all data transfered in hadoop is in serialized form
Hey Rajiv, thanks for checking out our blog. With regard to your query, yes, the serialized data will be stored in Hive. To insert data into table, Hive creates an object by using Java. To transfer java objects over network, the data should be serialized. Each field serialized by using Object inspector and finally serialized data stored in Hive table. Hope this helps. Cheers!
thanks sir for doubt clerification
please tell me the query how to split the information contained in the table in to another table
Hey Vissu, thanks for checking out our blog. You can insert existing data from a table into another table by using select query.
INSERT INTO table new_table select columnlist FROM secondtable where soma_conditions;
Hope this helps. Cheers!
i became much acquainted with HIVE with help of this blog.
We are happy we could help you understand Hive concepts. DO keep checking back in for more videos on all your favourite topics.
Nice blog ….i helped me a lot.
We are so happy we could help. Do keep checking back in for more blogs on all your favourite topics!