Friday, August 16, 2019

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: -
  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. select * from demo.employee  

Hive Load Data
Here, we can see the Null values at the position of unmatched data.

No comments:

Post a Comment

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...