Database Reference
In-Depth Information
Category Type
Description
Literal examples
array(1, 2)
[
a
]
Complex
An ordered collection of fields. The fields must all be
of the same type.
ARRAY
An unordered collection of key-value pairs. Keys
must be primitives; values may be any type. For a
particular map, the keys must be the same type, and
the values must be the same type.
MAP
map('a', 1, 'b', 2)
A collection of named fields. The fields may be of
different types.
STRUCT
A value that may be one of a number of defined data
types. The value is tagged with an integer (zero-in-
dexed) representing its data type in the union.
UNION
create_union(1, 'a',
63)
[
a
]
The literal forms for arrays, maps, structs, and unions are provided as functions. That is,
array
,
map
,
struct
, and
create_union
are built-in Hive functions.
Primitive types
Hive's primitive types correspond roughly to Java's, although some names are influenced
by MySQL's type names (some of which, in turn, overlap with SQL-92's). There is a
BOOLEAN
type for storing true and false values. There are four signed integral types:
TINYINT
,
SMALLINT
,
INT
, and
BIGINT
, which are equivalent to Java's
byte
,
short
,
int
, and
long
primitive types, respectively (they are 1-byte, 2-byte, 4-byte, and
8-byte signed integers).
Hive's floating-point types,
FLOAT
and
DOUBLE
, correspond to Java's
float
and
double
, which are 32-bit and 64-bit floating-point numbers.
The
DECIMAL
data type is used to represent arbitrary-precision decimals, like Java's
BigDecimal
, and are commonly used for representing currency values.
DECIMAL
val-
ues are stored as unscaled integers. The
precision
is the number of digits in the unscaled
value, and the
scale
is the number of digits to the right of the decimal point. So, for ex-
ample,
DECIMAL(5,2)
stores numbers between −999.99 and 999.99. If the scale is
omitted then it defaults to 0, so
DECIMAL(5)
stores numbers in the range −99,999 to
99,999 (i.e., integers). If the precision is omitted then it defaults to 10, so
DECIMAL
is