SAP

Web

Must Learn!

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
  • String Types
  • Date/Time Types
  • Complex Types

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 "guru99"

Data operations in Hive

From the above screen shot, we are doing two things

  • Creating database "guru99" in Hive
  • Displaying existing databases using "show" command
  • In the same screen, Database "guru99" name is displayed at the end when we execute the show command. Which means Database "guru99" is successfully created.

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 guru99

Data operations in Hive

In the above screenshot, we are doing two things

  • We are dropping database 'guru99' from Hive
  • Cross checking the same with "show" command
  • In the same screen, after checking databases with show command, database"guru99" does not appear inside Hive.
  • So we can confirm now that database "guru99" is dropped

 

YOU MIGHT LIKE: