Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




HIVE TABLES

There are two types of tables in HIVE, Managed and External.
Data in HIVE is stored in files and those files are stored inside the directories which have the same name as the table name.


Example :

Say we have created a table in HIVE named 'Employee'. Now behind the scenes HIVE will be creating a directory named 'Employee'. Then inside the 'Employee' directory files will be created which will hold the actual data of the 'Employee' table.



Where are the files and directories related to HIVE stored in HDFS?

All the files and directories related to HIVE are stored in HIVE's 'warehouse' directory by default. The default path of the 'warehouse' directory is '/user/hive/warehouse' .


Example :

Say we have created a database 'myNewDB'. Inside 'myNewDB' we have created a table 'Employee'. Now we have inserted some values in the 'Employee'. The directory structure looks somewhat like this :

/user/hive/warehouse/myNewDB.db/Employee/000000_0

The database 'myNewDB' is suffixed with .db. Inside which we find the 'Employee' directory. Finally we can see the file '000000_0', which contains actual data. Hadoop has given an arbitrary name for it. Overall the data is stored in the 'warehouse' directory.



What are Managed and External tables?

Depending on where the data is placed in HIVE there are two types of table in HIVE:


Managed table :

In managed tables the data is placed in the 'warehouse' directory and is completely managed and maintained by HIVE. However other technologies like pig and map reduce jobs can also access the data. And most importantly deleting managed table deletes the data along with the metadata.


External table :

In External tables the data is stored in some other directory and not in the 'warehouse' directory of HIVE. So the data is not managed by HIVE but HIVE can access the data in the external directory. And in this case deleting an external table does not delete the actual data.