Database Reference
In-Depth Information
equivalent to DECIMAL(10,0) . The maximum allowed precision is 38, and the scale
must be no larger than the precision.
There are three Hive data types for storing text. STRING is a variable-length character
string with no declared maximum length. (The theoretical maximum size STRING that
may be stored is 2 GB, although in practice it may be inefficient to materialize such large
values. Sqoop has large object support; see Importing Large Objects .) VARCHAR types are
similar except they are declared with a maximum length between 1 and 65355; for ex-
ample, VARCHAR(100) . CHAR types are fixed-length strings that are padded with trail-
ing spaces if necessary; for example, CHAR(100) . Trailing spaces are ignored for the
purposes of string comparison of CHAR values.
The BINARY data type is for storing variable-length binary data.
The TIMESTAMP data type stores timestamps with nanosecond precision. Hive comes
with UDFs for converting between Hive timestamps, Unix timestamps (seconds since the
Unix epoch), and strings, which makes most common date operations tractable.
TIMESTAMP does not encapsulate a time zone; however, the to_utc_timestamp and
from_utc_timestamp functions make it possible to do time zone conversions.
The DATE data type stores a date with year, month, and day components.
Complex types
Hive has four complex types: ARRAY , MAP , STRUCT , and UNION . ARRAY and MAP are
like their namesakes in Java, whereas a STRUCT is a record type that encapsulates a set of
named fields. A UNION specifies a choice of data types; values must match exactly one of
these types.
Complex types permit an arbitrary level of nesting. Complex type declarations must speci-
fy the type of the fields in the collection, using an angled bracket notation, as illustrated in
this table definition with three columns (one for each complex type):
CREATE TABLE complex (
c1 ARRAY<INT>,
c2 MAP<STRING, INT>,
c3 STRUCT<a:STRING, b:INT, c:DOUBLE>,
c4 UNIONTYPE<STRING, INT>
);
If we load the table with one row of data for ARRAY , MAP , STRUCT , and UNION , as
shown in the “Literal examples” column in Table 17-3 (we'll see the file format needed to
Search WWH ::




Custom Search