Hive - Load Data
Once the internal table has been created, the next step is to load the data into it. So, in Hive, we can easily load data from any file to the database.
Let's load the data of the file into the database by using the following command: -
load data local inpath '/home/codegyani/hive/emp_details' into table demo.employee;
Hive Load Data
Here, emp_details is the file name that contains the data.
Now, we can use the following command to retrieve the data from the database.
select * from demo.employee;
Hive Load Data
Hive Load Data
If we want to add more data into the current database, execute the same query again by just updating the new file name.
load data local inpath '/home/codegyani/hive/emp_details1' into table demo.employee;
Hive Load Data
Let's check the data of an updated table: -
Hive Load Data
In Hive, if we try to load unmatched data (i.e., one or more column data doesn't match the data type of specified table columns), it will not throw any exception. However, it stores the Null value at the position of unmatched tuple.
Let's add one more file to the current table. This file contains the unmatched data.
Hive Load Data
Here, the third column contains the data of string type, and the table allows the float type data. So, this condition arises in an unmatched data situation.
Now, load the data into the table.
load data local inpath '/home/codegyani/hive/emp_details2' into table demo.employee;
Hive Load Data
Here, data loaded successfully.
Let's fetch the records of the table.
select * from demo.employee
Hive Load Data
Here, we can see the Null values at the position of unmatched data.