Hive Data types

Hive supports several sizes of integer and floating-point types, a Boolean type, and character strings of arbitrary length. Hive v0.8.0 added types for timestamps and binary fields. The data types supported by Hive are

Numeric Types

  • TINYINT – 1-byte signed integer, from -128 to 127
  • SMALLINT – 2-byte signed integer, from -32,768 to 32,767
  • INT – 4-byte signed integer, from -2,147,483,648 to 2,147,483,647
  • BIGINT – 8-byte signed integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • FLOAT – 4-byte single precision floating point number
  • DOUBLE – 8-byte double precision floating point number
  • DECIMAL Introduced in Hive 0.11.0 with a precision of 38 digits. Hive 0.13.0 introduced user definable precision and scale

Integral literals are assumed to be INT by default, unless the number exceeds the range of INT in which case it is interpreted as a BIGINT, or if one of the following postfixes is present on the number.

Date/Time Types

  • TIMESTAMP – Only available starting with Hive 0.8.0. Supports traditional UNIX timestamp with optional nanosecond precision.
  • DATE – Only available starting with Hive 0.12.0. DATE values describe a particular year/month/day, in the form YYYY-­MM-­DD. For example, DATE ‘2013-­01-­01’. Date types do not have a time of day component. The range of values supported for the Date type is be 0000-­01-­01 to 9999-­12-­31, dependent on support by the primitive Java Date type.

String Types

  • STRING – String literals can be expressed with either single quotes (‘) or double quotes (“). Hive uses C-style escaping within the strings.
  • VARCHAR Only available starting with Hive 0.12.0. Varchar types are created with a length specifier (between 1 and 65355), which defines the maximum number of characters allowed in the character string.
  • CHAR Only available starting with Hive 0.13.0. Char types are similar to Varchar but they are fixed-length meaning that values shorter than the specified length value are padded with spaces but trailing spaces are not important during comparisons. The maximum length is fixed at 255.

Complex Types

  • arrays: ARRAY<data_type> – negative values and non-constant expressions are allowed as of Hive 0.14. Arrays in Hive are used the same way they are used in Java – Syntax: ARRAY<data_type>
  • maps: MAP<primitive_type, data_type> – negative values and non-constant expressions are allowed as of Hive 0.14. They are also similar to Java maps – Syntax: MAP<primitive_type, data_type>
  • structs: STRUCT<col_name : data_type [COMMENT col_comment], …>. Structs in Hive is similar to using complex data with comment.
  • union: UNIONTYPE<data_type, data_type, …> – Only available starting with Hive 0.7.0. Union types can at any one point hold exactly one of their specified data types. You can create an instance of this type using the create_union UDF.
Hive shell
HiveQL

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?