Monday 4 July 2022

HIVE: Data types

Hive data types are categorized into two types.

a.   Primitive types

b.   Complex types

 

Following table summarizes primitive types.

 

Data type

Description

Example

TINYINT

Occupies 1 byte. Minimum value is -128 and maximum value is 128. Postfix is Y.

123Y

SMALLINT

Occupies 2 bytes. Minimum value is -32768 and maximum value is 32767. Postfix is S.

12345S

INT

Occupies 4 bytes. Minimum value is -2,147,483,648 and maximum value is 2,147,483,647.

12345678

BIGINT

Occupies 8 bytes. Minimum value is 9,223,372,036,854,775,808 and maximum value is 9,223,372,036,854,775,807. Postfix is L.

123L

FLOAT

4 bytes single precision number.

1.2345

DOUBLE

8 bytes double precision number

1.2345

BOOLEAN

Represent TRUE or FALSE value

TRUE

STRING

Collection of characters represented in either single quotes or double quotes. Maximum size is around 2GB.

'hello wolrd', "Hello World"

CHAR

Maximum length is 255 characters

'hello wolrd', "Hello World"

VARCHAR

Maximum length is 65535 characters.

'hello wolrd', "Hello World"

DATE

Specify year, month, and day in the format of YYYY-MM-DD. The range of dates is from 0000-01-01 to 9999-12-31.

2020-01-08

TIMESTAMP

This describes a specific year, month, day, hour, minute, second, and millisecond in the format of YYYY-MM-DD HH:MM:SS.fff.

2020-01-08 111.23.34.123

 

Example

create table numeric_data_types_demo(
a TINYINT,
b SMALLINT,
c INT,
d BIGINT,
e FLOAT,
g DOUBLE,
h BOOLEAN,
i STRING,
j CHAR(10),
k VARCHAR(123),
l DATE,
m TIMESTAMP,
n DECIMAL,
o DECIMAL(10, 2)
)

hive> create table numeric_data_types_demo(
    > a TINYINT,
    > b SMALLINT,
    > c INT,
    > d BIGINT,
    > e FLOAT,
    > g DOUBLE,
    > h BOOLEAN,
    > i STRING,
    > j CHAR(10),
    > k VARCHAR(123),
    > l DATE,
    > m TIMESTAMP,
    > n DECIMAL,
    > o DECIMAL(10, 2)
    > );
OK
Time taken: 0.061 seconds

 

Get the columns and their respective data types information.

hive> describe numeric_data_types_demo;
OK
a                       tinyint                                     
b                       smallint                                    
c                       int                                         
d                       bigint                                      
e                       float                                       
g                       double                                      
h                       boolean                                     
i                       string                                      
j                       char(10)                                    
k                       varchar(123)                                
l                       date                                        
m                       timestamp                                   
n                       decimal(10,0)                               
o                       decimal(10,2)                               
Time taken: 0.064 seconds, Fetched: 14 row(s)

 

Following table summarizes the complex types supported in HIVE

 

Data type

Description

Example

ARRAY

List of items of same type

[1, 2, 3, 4]

[1.2, 3.4, 5.6]

MAP

Represent set of key,value pairs

{1 : "Krishna", 2 : "Ram"}

STRUCT

Collection of elements of different type.

Address struct<city:string,state:string,country:string,pin:bigint>

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment