Because of the need to use hive SQL for data queries, and the combination of several different types of fields, the document correlation and data for hive SQL are known, and hive supports the conversion between most of the underlying data types.
So, what data types does hive natively support?
From the hive built-in data types, the data types supported by hive include the following:
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 |
And some data data types: including array arrays, map key-value pairs, struct structures, union unions, and so on.
As you can see, hive supports the types of data that are used at all times.
At the same time, hive supports conversions between most of these data types.
Some of the underlying data types support implicit conversions, meaning that the source type can be used as the target type directly during use, and types that support data type implicit include:
|
Boolean |
tinyint |
smallint |
int |
bigint |
float |
Double |
decimal |
string |
varchar |
timestamp |
Date |
binary |
Boolean |
True |
False |
False |
False |
False |
False |
False |
False |
False |
False |
False |
False |
False |
tinyint |
False |
True |
True |
True |
True |
True |
True |
True |
True |
True |
False |
False |
False |
smallint |
False |
False |
True |
True |
True |
True |
True |
True |
True |
True |
False |
False |
False |
int |
False |
False |
False |
True |
True |
True |
True |
True |
True |
True |
False |
False |
False |
bigint |
False |
False |
False |
False |
True |
True |
True |
True |
True |
True |
False |
False |
False |
float |
False |
False |
False |
False |
False |
True |
True |
True |
True |
True |
False |
False |
False |
Double |
False |
False |
False |
False |
False |
False |
True |
True |
True |
True |
False |
False |
False |
decimal |
False |
False |
False |
False |
False |
False |
False |
True |
True |
True |
False |
False |
False |
string |
False |
False |
False |
False |
False |
False |
True |
True |
True |
True |
False |
False |
False |
varchar |
False |
False |
False |
False |
False |
False |
True |
True |
True |
True |
False |
False |
False |
timestamp |
False |
False |
False |
False |
False |
False |
False |
False |
True |
True |
True |
False |
False |
Date |
False |
False |
False |
False |
False |
False |
False |
False |
True |
True |
False |
True |
False |
binary |
False |
False |
False |
False |
False |
False |
False |
False |
False |
False |
False |
False |
True |
At the same time, we can use cast to explicitly convert one type of data to another type of data.
If Hive does not support this type of conversion, an error will be made when using cast for conversion:
If you convert bigint to binary
CAST ((9223372036854775807-unix_timestamp ()) as binary)
The "invalid cast from bigint to binary" error is reported.
The past memory summed up very well, the above content is mostly from here, and made a certain processing summary.