Types of data in Hive

Tram Ho

In this section we will look through the types of data related to creating tables in Hive. The entire data types in Hive are divided into 4 categories as follows:

  • Column types
  • Literals
  • Null Values
  • Complex Types

Column Types

Used to make the data type of columns in Hive. These include:

Intact type

Raw data types can be specified using the raw data type, INT. When the data type range exceeds INT (4-byte integer signed, from -2,147,483,648 to 2,147,483,647), we will use BIGINT (8-byte integer signed from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807) and if small limit than INT, we can use SMALLINT (2-byte integer signed) or TINYINT (1-byte integer signed). The following table describes the various data types:



The String type

String data types can be specified with parentheses (”) or double quotes (“”). It contains two data types: VARCHAR and CHAR.

Data typelength
Varchar1 -> 65355


Hive supports Unix time with an accuracy of up to nanoseconds. Support the java.sql.Timestamp format: “YYYY-MM-DD HH: MM: SS.fffffffff” and the format “yyyy-mm-dd hh: mm: ss.ffffffffff”.


The DATE value is described in the year / month / day format as {{YYYY-MM-DD}}.


The Decimal format in Hive is similar to the Java Big Decimal format. It is used to represent decimals with constant precision. Syntax and example:


Types of floating point

These are decimal numbers, assumed to be Double.

Decimal type

Decimal are also floating-point numbers with a higher range than the Double type. Decimal’s range is from (-10 ^ 308 to 10 ^ 308)

Null Value

Missing values ​​are indicated by the special value Null.

Complex types

Here are the complex data types:


  • Arrays: ARRAY <data_type>
  • Maps: MAP <primitive_type, data_type>
  • Structs: STRUCT <col_name: data_type [COMMENT col_comment], …>
  • Union: UNIONTYPE <data_type, data_type, …>
Chia sẻ bài viết ngay

Nguồn bài viết : Viblo