Wednesday, March 28, 2018

Hive - Database and Table Creation

The traditional database works on the fact that they control the complete data storage system.
It will check if the data that is being written follows the constraints , datatype ,lengths etc.
The above property is called SCHEMA ON WRITE

HIVE does not follow above all as it does not have it's own storage system and rely on the HDFS for it's data storage.
HIVE can read any data that is kept in the HDFS which is created , updated or sometimes the data got damaged also.
This property is called SCHEMA ON READ.

So, Let us start and check the different databases available in our cluster.
 
It will display all the databases available in the HIVE.


We should note that HIVE contains a default database if we do not specify the database name , the default database will get provoked.

Normally , when we are working with a large data set and a number of databases ,we forget that in which DB we are working .we can set a property to identify the current DB using the below command.

 

Creating a DB :- We can create our own db using the simple command .

 

Using the particular DB :-We can use the particular db using the use keyword followed by the database name.

 

Whenever we create a database in the HIVE ,a directory is created and the tables are stored in the sub directories.Exception is the default database.

The default location is the hive.metastore.warehouse.dir.
We can check the directory for the default db in the below location:-
 
 

We can switch the database directory at the time of database creation.

Dropping a database :- We can drop a database using "drop database database_name;"
However, it will throw ana error if it contains tables inside the database.
In order to override this property, we can use
Drop database database_name cascade;

Using the cascade keyword will drop all the tables , then the db and finally all the directory associated with it.

No comments:

Post a Comment

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...