Big Data - Hive

Back to Course

Lesson Description

Lession - #1129 Hive Data Types

This part takes you through the various information types in Hive, which are engaged with the table creation. Every one of the information types in Hive are grouped into four types, given as follows:

  • Column Types
  • Literals
  • Null Values
  • Complex Types

Column Types
Column type are used as column data types of Hive. They are as follows:
Integral Types
Integer type data can be specified using integral data types, INT. When the data range exceeds the range of INT, you need to use BIGINT and if the data range is smaller than the INT, you use SMALLINT. TINYINT is smaller than SMALLINT. The following table depicts various INT data types:
Type Postfix Example
INT - 10
String Types
String type data types can be specified using single quotes (' '>
or double quotes (" ">
. It contains two data types: VARCHAR and CHAR. Hive follows C-types escape characters. The following table depicts various CHAR data types:
Data Type Length
VARCHAR 1 to 65355
CHAR 255
It supports traditional UNIX timestamp with optional nanosecond precision. It supports java.sql.Timestamp format “YYYY-MM-DD HH:MM:SS.fffffffff” and format “yyyy-mm-dd hh:mm:ss.ffffffffff”.
DATE values are described in year/month/day format in the form {{YYYY-MM-DD}}.
The DECIMAL type in Hive is as same as Big Decimal format of Java. It is used for representing immutable arbitrary precision. The syntax and example is as follows:

DECIMAL(precision, scale>
Union Types
Union is a collection of heterogeneous data types. You can create an instance using create union. The syntax and example is as follows:

UNIONTYPE<int, double, array<string>, struct<a:int,b:string>>

The following literals are used in Hive:
Floating Point Types
Floating point types are nothing but numbers with decimal points. Generally, this type of data is composed of DOUBLE data type.
Decimal Type
Decimal type data is nothing but floating point value with higher range than DOUBLE data type. The range of decimal type is approximately -10-308 to 10308.
Null Value
Missing values are represented by the special value NULL.
Complex Types
The Hive complex data types are as follows:
Arrays in Hive are used the same way they are used in Java.
Syntax: ARRAY<data_type>
Maps in Hive are similar to Java Maps.
Syntax: MAP<primitive_type, data_type>
Structs in Hive is similar to using complex data with comment.
Syntax: STRUCT<col_name : data_type [COMMENT col_comment], ...>