Data insertion into Hive Table
924 views
Oct 24, 2024
Data insertion into Hive Table Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
View Video Transcript
0:00
In this video we are discussing data insertion into a table
0:03
In the previous videos we have shown you that how to create a database and how to create
0:08
one table. Now we shall discuss that how to insert data onto those created tables
0:15
Data insertion on the table can be done in two different ways, either directly issuing
0:19
the insert command where we'll be passing our data so that data can get inserted into
0:24
the table. And another way is that from the data file we can fetch data to insert it in the data
0:29
as the records in the table. So we shall be discussing both of them
0:33
So let us discuss one by one. At first, we are starting with that how to insert data into hype table
0:40
So we are starting with that we can add data from a file
0:44
So how to fetch data from the file so that my data will get inserted in the hype
0:50
So we can add data from a file stored in the HDFS directory
0:55
And the syntax will be like this, that is load data in path
0:59
path has to be mentioned into table then the table name has to be mentioned here
1:05
So the command is load data in path. The path will be mentioned where we can find the file containing the data and then into table and then table name and semicolon We should remember that the fields terminated by type must be matched with the fields terminated
1:24
delimited in an actual data file. That means, whatever the terminators were using here and they should match with each other
1:32
Otherwise, the data insertion may not be successful. So now let us go for another type of insertion
1:40
is we can also insert data without using a file. That means this insertion syntax is very
1:46
similar with the RDBMS insert query syntax. So, syntax will be insert into table, then table
1:53
name values, then within first brackets, val 1 comma val 2 comma dot dot dot, then we can have the
1:59
valend and then we'll be having the closing fast bracket. So we have seen that there are two ways
2:06
to insert data onto the height table. One is from the data file and another
2:09
the one is using our insert query. When you are going for the data file insertion, that is
2:16
the data file content will be inserted onto the hype, in that case the delimiter should match
2:21
That means the data file must have the data separated by some delimiters maybe comma or some other characters and that delimiter must be matching So otherwise the data insertion will be unsuccessful and in case of directly inserting data onto the high table
2:36
the query syntax is very similar with the rdbMS insert query syntax so let us go for one
2:43
practical demonstration for the better understanding on this query executions in this demonstration
2:49
we shall insert data from the sdfs file so here we are selecting
2:54
one file so it is our sdfs route and then we're having this one as had do my files if you click
3:03
here we're having one file that is a student underscore info c sb so let me at first check the
3:09
current content of this file so i shall go for this control alter t so one new terminal has got
3:16
opened so let me check what is the current content of the file that is the student underscore
3:22
info c sb residing under the the residing under the folder that is the Hadoop my files so here the command is
3:29
HDFS then DFS then minus CAT then Hadoop root then you shall go for Hadoop my
3:38
files then we shall go for Hadoop my files and then we shall go for student I need not to type the full one I can also put the wild card character
3:51
So the file content is this is a file content. You can find that this file content
3:57
We can easily access this file content. That is Amit Electronics, Kolkata. So then Dinesh, Computer Science, Chennai, Kusol, Fedix, Kolkata, Roctim, Computer
4:06
Science, Delhi and Tapos, Electronics, Mumbai. So from this file that is a student high underscore info c sb I want to load my data onto my
4:17
onto my database that is a hype database whatever you have created so let us go for the same
4:27
So here our our table name is our stood so in this stood I'm going to put that one so how to do so we shall go for this one as load
4:36
then data then in path then within single code I'm supposed to write the
4:44
full thing so that is our my that is the hardup my files so remember that hard of
4:53
was written in the capital letters M and F so how do ing files so m and f
4:58
should be in capital letters
#Computer Education
#Data Management
#Enterprise Technology
#Programming