Hive Data Types & Create, Drop Database

Data types in Hive

Data types are very important elements in Hive query language and data modeling. For defining the table column types, we must have to know about the data types and its usage.

The following gives brief overview of some data types present in Hive:

These are

Numeric Types:

Type Memory allocation
TINY INT Its 1-byte signed integer (-128 to 127)
SMALL INT 2-byte signed integer (-32768 to 32767)
INT 4 –byte signed integer ( -2,147,484,648 to 2,147,484,647)
BIG INT 8 byte signed integer
FLOAT 4 – byte single precision floating point number
DOUBLE 8- byte double precision floating point number
DECIMAL We can define precision and scale in this Type

String Types:

Type Length
CHAR 255
VARCHAR 1 to 65355
STRING We can define length here(No Limit)

Date/Time Types:

Type Usage
Timestamp Supports traditional Unix timestamp with optional nanosecond precision
Date
  • It's in YYYY-MM-DD format.
  • The range of values supported for the Date type is be 0000-01-01 to 9999-12-31, dependent onsupport by the primitive Java Date type

Complex Types:

Type Usage
Arrays ARRAY<data_type> Negative values and non-constant expressions not allowed
Maps MAP<primitive_type, data_type> Negative values and non-constant expressions not allowed
Structs STRUCT<col_name :datat_type, ….. >
Union UNIONTYPE<data_type, datat_type, ……>

Creation and dropping of Database in Hive:

Create Database:

For creating database in Hive shell, we have to use the command as shown in syntax below:-

Syntax:

Create database <DatabaseName>

Example: -Create database "gtupapers"

Data operations in Hive

From the above screen shot, we are doing two things

Drop Database:

For Dropping database in Hive shell, we have to use the "drop" command as shown in syntax below:-

Syntax:

Drop database <DatabaseName>

Example:-

Drop database gtupapers

Data operations in Hive

In the above screenshot, we are doing two things

 

YOU MIGHT LIKE: