You are currently viewing Hive Data Types – Primitive | Complex

Hive supports several date types like

Advertisements

Hive Numeric Types

Below are Numeric Types Hive support and their sizes.

Numeric TypesDescription
TINYINT1-byte signed integer, from -128 to 127
SMALLINT2-byte signed integer, from -32,768 to 32,767
INT/INTEGER4-byte signed integer, from -2,147,483,648 to 2,147,483,647
BIGINT8-byte signed integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
FLOAT4-byte single precision floating point number
DOUBLE8-byte double precision floating point number
DOUBLE PRECISIO NAlias for DOUBLE, only available starting with Hive 2.2.0
DECIMALIt accepts a precision of 38 digits.
NUMERICSame as DECIMAL type.
Table1 – Hive Numeric Types

Hive Date/Time Types

Below are Hive Date and Timestamp types, these were not available in the initial versions of the Hive and added in later releases. Date type is used to store just Date and Timestamp is used to store both date and time.

Hive provides several Date & Time functions, you should use these to perform any date & time operations.

Date/Time TypesDescription
TIMESTAMPAccepts Both Date and Time
DATEAccepts just Date
INTERVALInterval
Table2 – Hive Date/Time Types

Hive String Types

Similar to SQL, Hive also supports CHAR and VARCHAR types, and additionally, it also supports STRING type.

Hive provides several String functions, you should use these to perform any string operations.

String TypesDescription
STRINGThe string is an unbounded type. Not required to specify the lenght. It can accept max up to 32,767 bytes.
VARCHARVariable length of characters. It is bounded meaning you still need to specify the length like VARCHAR(10).
CHARFixed length of Characters. if you define char(10) and assigning 5 chars, the remaining 5 characters space will be wasted.
Table3 – Hive String Types

Hive Misc Types

Misc TypesDescription
BOOLEANAccepts TRUE/FALSE values
BINARYOnly available starting with Hive 0.8.0
Table4 – Hive Boolean/Binary Types

Hive Complex Types

Similar to Spark, Hive also support complex data types which includes Array, Map, Struct and union. Array is used to store the list of elements. Map is used to store key/value pair. Struct is for parent and child assosiations.

To work with Complex types, you should use Hive Collection Map & Array functions

Complex TypesDescription
ArraysARRAY<data_type>
MapsMAP<primitive_type, data_type>
Structs STRUCT<col_name : data_type [COMMENT col_comment], ...>
UnionUNIONTYPE<data_type, data_type, …>
Note: Only available starting with Hive 0.7.0.
Table5 – Hive Complex Types

Happy Learning !!

Leave a Reply