Summary -
In this topic, we described about the below sections -
In Hive, the below Data types are normally used to declare a column of the table. There are two types of data types available in Hive.
- Primitive
- Complex
Let’s discuss about each type in detail.
Primitive Data Types -
These are the basic data types. These data types are directly associated with columns in the table. Primitive data types are normally 4 types at high level.
- Integer
- Boolean
- Floating Point
- String
Primitive Type | Sub data Type | Description | Length | Range |
---|---|---|---|---|
Integers | ||||
TINYINT | Signed Integer | 1 Byte | -128 to 127 | |
SMALLINT | Signed Integer | 2 Byte | -32768 to 32767 | |
INT | Signed Integer | 4 Byte | -2147483648 .. 2147483647 | |
BIGINT | Signed Integer | 8 Byte | 9223372036854775808 .. 9223372036854775807 | |
Boolean Type | BOOLEAN | True /False | TRUE/ FLASE | |
Floating point | ||||
FLOAT | Single Precision floating point number | 4 Byte | 1.40129846432481707e-45 .. 3.40282346638528860e+38 | |
DOUBLE | Double Precision floating point number | 8 Byte | 4.94065645841246544e-324d .. 1.79769313486231570e+308 | |
String | STRING | sequence of characters in a specified character set | Max 2GB | 32,767 |
Binary | Binary | Variable length binary data | ||
TIMESTAMP | Timestamp | Timestamp with no second precision | 1400-01-01 to 9999-12-31 |
Below are the declarations of Primitive data types.
Data Type | Declaration |
---|---|
TINYINT | Column_name TINYINT |
SMALLINT | Column_name SMALLINT |
INT | Column_name INT |
BIGINT | Column_name BIGINT |
BOOLEAN | Condition1 AND/OR/NOT/&&/||/! Condition2 |
FLOAT | Column_name FLOAT |
DOUBLE | Column_name DOUBLE |
STRING | Column_name STRING |
Binary | Column_name BINARY |
Timestamp | Column_name TIMESTAMP |
Below is conversion table for all primitive data types.
- “Y” Represents the data type can convert from source to destination.
- “N” represents the data type can’t be converted from source to destination.
Complex data types -
Complex data types can be built up from Primitive data types. Complex data types permit an arbitrary level of nesting. Complex declarations must specify the data type in the field’s collection.
Complex types are mainly of 3 types.
- Arrays (indexable lists)
- Maps (key-value tuples)
- Structs
Complex Type | Description |
---|---|
Array | An order collection of fields.All fields in array must be of same type.Elements can be access by [n] and n is an index of the array. |
Map | An ordered collection of key-value pairs.Elements can be accessed through [‘element name’] notation.Key must be primitive’s type.Values can be of any type (either primitive or complex). A single map should contain all keys same type and all values must be same type. |
Structs | A collection of name fields.The elements within the type can be accessed through (.) notation.May have different data types. |
Below are the declarations of Primitive data types.
Data Type | Declaration |
---|---|
Array | ARRAY<data_type> |
Map | MAP<primitive_type, data_type> |
Structs | STRUCT<col_name: data_type [COMMENT col_comment], col_name: data_type...> |
Below is conversion table for all primitive data types.
Array | Map | Structs | |
---|---|---|---|
Array | Y | N | N |
Map | N | Y | N |
Structs | Y | N | N |
- “Y” Represents the data type can convert from source to destination.
- “N” represents the data type can’t be converted from source to destination.