table of Contents
3. Hive data type
3.1 Basic data types
Hive data type | Java data types | length | example |
---|---|---|---|
TINYINT | byte | 1byte signed integer | 20 |
SMALINT | short | 2byte signed integer | 20 |
INT |
int | 4byte signed integer | 20 |
BIGINT | long | 8byte signed integer | 20 |
BOOLEAN | boolean | Boolean type, true or false | TRUE FALSE |
FLOAT | float | Single precision floating point | 3.14159 |
DOUBLE |
double | Double precision floating point | 3.14159 |
STRING |
string | Character series. You can specify the character set. You can use single or double quotes. | ‘now is the time’ “for all good men” |
TIMESTAMP | Time type | '2013-01-31 00:13:00.345’ | |
BINARY | Byte array (binary) | 1010 |
The red label is a commonly used data type;
For Hive, the String type is equivalent to the varchar type of the database, which is a variable string, but it cannot declare the maximum number of characters that can be stored in it.
3.2 Collection data types
type of data | description | Syntax example |
---|---|---|
STRUCT | It is equivalent to an object without methods in the Java language, only attributes. For example, if the data type of a certain column is STRUCT{first STRING, last STRING}, then the first element can 字段.first be referenced by. |
struct() |
MAP | MAP is a set of key-value pair tuples, and data can be accessed using array notation. For example, if the data type of a column is MAP, and the key->value pairs are'first'->'John' and'last'->'Doe', then you can 字段名[‘last’] get the last element by |
map() |
ARRAY | An array is a collection of variables with the same type and name. These variables are called elements of the array, and each array element has a number, which starts from zero. For example, if the array value is ['John','Doe'], then the second element can 数组名[1] be referenced by. |
Array() |
3.3 Type conversion
Can use CAST operation display for data type conversion
For example, CAST('1' AS INT) will convert the string '1' into an integer 1. If the coercion fails, such as executing CAST('X' AS INT), the expression returns NULL.