Hive supports several date types like
- Hive Numeric Types
- Hive Date & Time Types
- Hive String Types
- Hive Misc Types (Boolean & Binary)
- Hive Complex Types (Array, Map, Struct)
Hive Numeric Types
Below are Numeric Types Hive support and their sizes.
|TINYINT||1-byte signed integer, from |
|SMALLINT||2-byte signed integer, from |
|INT/INTEGER||4-byte signed integer, from -2,147,483,648 to 2,147,483,647|
|BIGINT||8-byte signed integer, from |
|FLOAT||4-byte single precision floating point number|
|DOUBLE||8-byte double precision floating point number|
|DOUBLE PRECISIO N||Alias for DOUBLE, only available starting with Hive 2.2.0|
|DECIMAL||It accepts a precision of 38 digits.|
|NUMERIC||Same as DECIMAL type.|
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.
|TIMESTAMP||Accepts Both Date and Time|
|DATE||Accepts just Date|
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||The string is an unbounded type. Not required to specify the lenght. It can accept max up to 32,767 bytes.|
|VARCHAR||Variable length of characters. It is bounded meaning you still need to specify the length like VARCHAR(10).|
|CHAR||Fixed length of Characters. if you define char(10) and assigning 5 chars, the remaining 5 characters space will be wasted.|
Hive Misc Types
|BOOLEAN||Accepts TRUE/FALSE values|
|BINARY||Only available starting with Hive 0.8.0|
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
|Union||UNIONTYPE<data_type, data_type, …>|
Note: Only available starting with Hive 0.7.0.
Happy Learning !!