Tutorial index: Big Data for Beginners: tutorial series
Primitive Types
| Hive type | Java type | Length | Example |
|---|---|---|---|
| TINYINT | byte | 1-byte signed integer | 20 |
| SMALINT | short | 2-byte signed integer | 20 |
| INT | int | 4-byte signed integer | 20 |
| BIGINT | long | 8-byte 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 sequence. Character set can be specified. Single or double quotes both work. | ‘now is the time’ “for all good men” |
| TIMESTAMP | Time type | ||
| BINARY | Byte array |
Collection Types
| Type | Syntax and description |
|---|---|
| STRUCT | Similar to struct in C — elements are accessed with dot notation. For example, if a column’s type is STRUCT{first STRING, last STRING}, the first element is referenced as field.first. |
| MAP | A set of key-value tuples accessed with array notation. For example, a column of type MAP holding 'first'->'John' and 'last'->'Doe' lets you read the last element via field['last']. |
| ARRAY | A collection of variables sharing the same type and name. These variables are the array’s elements, numbered starting from zero. For an array value of ['John', 'Doe'], the second element is referenced as arrayName[1]. |
Type Conversion
Hive’s atomic types can be converted implicitly, similar to Java. If an expression uses INT, a TINYINT is automatically promoted to INT, but Hive will not convert in reverse: if an expression uses TINYINT, an INT will not be narrowed to TINYINT — it returns an error unless you use a CAST.
Implicit Conversion Rules
- Any integer type can be implicitly converted to a wider-range type: TINYINT to INT, INT to BIGINT.
- All integer types, FLOAT, and STRING can be implicitly converted to DOUBLE.
- TINYINT, SMALLINT and INT can all be converted to FLOAT.
- BOOLEAN cannot be converted to any other type.
Explicit Conversion with CAST
For example, CAST('1' AS INT) converts the string '1' into the integer 1. If the cast fails — say CAST('X' AS INT) — the expression returns NULL.
