The built-in data types of hive can be divided into two main categories: (1), underlying data type, (2), and complex data types. Among them, the underlying data types are: Tinyint,smallint,int,bigint,boolean,float,double,string,binary,timestamp,decimal,char,varchar,date. The following table lists the bytes of these underlying types and the versions from which these types are supported.
Data type |
Occupied bytes |
Start Support version |
TINYINT |
1byte,-128 ~ 127 |
|
SMALLINT |
2byte,-32,768 ~ 32,767 |
|
Int |
4byte,-2,147,483,648 ~ 2,147,483,647 |
|
BIGINT |
8byte,-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 |
|
BOOLEAN |
|
|
FLOAT |
4byte Single Precision |
|
DOUBLE |
8byte Double Precision |
|
STRING |
|
|
BINARY |
|
Support Starting from Hive0.8.0 |
TIMESTAMP |
|
Support Starting from Hive0.8.0 |
DECIMAL |
|
Support Starting from Hive0.11.0 |
CHAR |
|
Support Starting from Hive0.13.0 |
VARCHAR |
|
Support Starting from Hive0.12.0 |
DATE |
|
Support Starting from Hive0.12.0 |
Complex types include array,map,struct,union, which are composed of underlying types.
The Array:array type consists of a series of elements of the same data type that can be accessed by subscript. For example, there is an array type variable fruits, which is made up of [' Apple ', ' orange ', ' Mango '], then we can access the element orange by fruits[1], because the subscript of array type is starting from 0;
Map:map contains key->value key-value pairs that can be accessed by key. For example, "UserList" is a map type, where username is Key,password is value, then we can userlist[' username ' to get this user corresponding password;
Struct:struct can contain elements of different data types. These elements can be "point syntax" to get the required elements, such as user is a struct type, then you can get the address of the user through user.address.
Union:uniontype, he was supported from Hive 0.7.0.
Create a table that contains the type of replication as follows
CREATE TABLE Employees ( name STRING, FLOAT, subordinates ARRAY<STRING >, deductions MAP<FLOAT>, address STRUCT<street:string, city:string, state:string, zip:INT> by (country string, state string);
Hive built-in data type