Hive Data Types
Data Types in Hive define the kind of values that can be stored in each column of a table. For example,
- A name should be stored as text (STRING).
- A price should be stored as a number (DOUBLE).
- A date of birth should be stored as a DATE.
Choosing the right data type ensures that your queries work correctly and that Hive can store your data efficiently.
Types of Data Types -
Hive offers three broad categories of data types:
- Primitive Data Types
- Collection Data Types
- Complex Data Types
Primitive Data Types -
These are the basic building blocks of data in Hive. They store simple values like numbers, text, or dates.
Data Type | Description | Length | Range |
---|---|---|---|
TINYINT | Very small integer | 1 Byte | -128 to 127 |
SMALLINT | Small integer | 2 Byte | -32768 to 32767 |
INT | Regular integer | 4 Byte | -2147483648 .. 2147483647 |
BIGINT | Large integer | 8 Byte | 9223372036854775808 .. 9223372036854775807 |
FLOAT | Single precision decimal | 4 Byte | 1.40129846432481707e-45 .. 3.40282346638528860e+38 |
DOUBLE | Double precision decimal | 8 Byte | 4.94065645841246544e-324d .. 1.79769313486231570e+308 |
DECIMAL(p,s) | Precise decimal values | p, s | DECIMAL(10,2) stores 12345.67 |
STRING | Text values | Max 2GB | 32,767 |
VARCHAR(n) | Text up to ‘n’ length | n | |
CHAR(n) | Fixed-length text | n | CHAR(4) stores 'Test' |
BOOLEAN | True or False | True or False | TRUE or FLASE |
DATE | Calendar date | 1400-01-01 to 9999-12-31 | |
TIMESTAMP | Date with time | 1400-01-01 00:00:00 to 9999-12-31 00:00:00 |
Here is the 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.

Examples -
Scenario: Using different primitive types:
CREATE TABLE product_data (
product_id INT,
product_name STRING,
price DOUBLE,
available BOOLEAN
);
This stores product information, where each field has the right data type for its value.
Collection Data Types -
Sometimes, you need to store multiple values inside one field. That’s where collection types come in. They allow you to group multiple pieces of information together.
Complex Type | Description | Example |
---|---|---|
Array | Stores a list of values of the same type | ARRAY<STRING> → ['Apple', 'Banana'] |
Map | Stores key-value pairs | MAP<STRING, INT> → {'Math': 90, 'English': 85} |
Structs | Stores multiple fields as a single object | STRUCT<name:STRING, age:INT> |
Here is the conversion table for all collection 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.
Array | Map | Structs | |
---|---|---|---|
Array | Y | N | N |
Map | N | Y | N |
Structs | Y | N | N |
Examples -
Scenario: Using ARRAY and MAP:
CREATE TABLE student_data (
student_id INT,
student_name STRING,
subjects ARRAY<STRING>,
marks MAP<STRING, INT>
);
This table can store multiple subjects and their marks for each student in one row.
Complex Data Types -
Complex types are nested versions of the collection types where you combine them to create more advanced structures.
Examples -
CREATE TABLE company_data (
company_id INT,
company_name STRING,
employees ARRAY<STRUCT<emp_name:STRING, emp_salary:DOUBLE>>
);
This means each company can have an array of employees, and for each employee, you store both name and salary.