...
Numeric Types
TINYINT
(1-byte signed integer, from-128
to127
)SMALLINT
(2-byte signed integer, from-32,768
to32,767
)INT/INTEGER (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
to9,223,372,036,854,775,807
)FLOAT
(4-byte single precision floating point number)DOUBLE
(8-byte double precision floating point number)DOUBLE PRECISION (alias for DOUBLE, only available starting with Hive 2.2.0)
DECIMAL
NUMERIC
(same asDECIMAL
, starting with Hive 3.0.0)
Date/Time Types
TIMESTAMP
(Note: Only available starting with Hive 0.8.0)DATE
(Note: Only available starting with Hive 0.12.0)INTERVAL
(Note: Only available starting with Hive 1.2.0)
String Types
STRING
VARCHAR
(Note: Only available starting with Hive 0.12.0)CHAR
(Note: Only available starting with Hive 0.13.0)
...
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.
Type | Postfix | Example |
---|---|---|
TINYINT | Y | 100Y |
SMALLINT | S | 100S |
BIGINT | L | 100L |
Info | ||
---|---|---|
| ||
|
...
Timestamps are interpreted to be timezoneless and stored as an offset from the UNIX epoch. Convenience UDFs for conversion to and from timezones are provided (to_utc_timestamp
, from_utc_timestamp
).
All existing datetime UDFs (month, day, year, hour, etc.) work with the TIMESTAMP
data type.
Timestamps in text files have to use the format yyyy-mm-dd hh:mm:ss[.f...]
. If they are in another format, declare them as the appropriate type (INT, FLOAT, STRING, etc.) and use a UDF to convert them to timestamps.
Timestamps in Parquet files may be stored as int64 (as opposed to int96) by setting hive.parquet.write.int64.timestamp=true
and hive.parquet.timestamp.time.unit
to a default storage time unit. ("nanos", "micros",
"millis"
; default: "micros"
). Note that because only 64 bits are stored, int64 timestamps stored as "nanos"
will be stored as NULL if outside the range of 1677-09-21T00:12:43.15 and 2262-04-11T23:47:16.8.
On the table level, alternative timestamp formats can be supported by providing the format to the SerDe property "timestamp.formats" (as of release 1.2.0 with HIVE-9298). For example, yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd'T'HH:mm:ss.
...
Date types can only be converted to/from Date, Timestamp, or String types. Casting with user-specified formats is documented here.
Valid casts to/from Date type | Result |
---|---|
cast(date as date) | Same date value |
cast(timestamp as date) | The year/month/day of the timestamp is determined, based on the local timezone, and returned as a date value. |
cast(string as date) | If the string is in the form 'YYYY-MM-DD', then a date value corresponding to that year/month/day is returned. If the string value does not match this formate, then NULL is returned. |
cast(date as timestamp) | A timestamp value is generated corresponding to midnight of the year/month/day of the date value, based on the local timezone. |
cast(date as string) | The year/month/day represented by the Date is formatted as a string in the form 'YYYY-MM-DD'. |
Intervals
Supported Interval Description | Example | Meaning | Since | ||
---|---|---|---|---|---|
Intervals of time units: SECOND / MINUTE / DAY / MONTH / YEAR | INTERVAL '1' DAY | an interval of 1 day(s) | Hive 1.2.0 (HIVE-9792). | ||
Year to month intervals, format: SY-M S: optional sign (+/-) | INTERVAL '1-2' YEAR TO MONTH | shorthand for: INTERVAL '1' YEAR + | Hive 1.2.0 (HIVE-9792). | ||
Day to second intervals, format: SD H:M:S.nnnnnn S: optional sign (+/-) D: day countH: hoursM: minutes S: seconds nnnnnn: optional nanotime | INTERVAL '1 2:3:4.000005' DAY | shorthand for: INTERVAL '1' DAY+ | Hive 1.2.0 (HIVE-9792). | ||
Support for intervals with constant numbers | INTERVAL 1 DAY | aids query readability / portability | Hive 2.2.0 (HIVE-13557). | ||
Support for intervals with expressions: | INTERVAL (1+dt) DAY | enables dynamic intervals | Hive 2.2.0 (HIVE-13557). | ||
Optional usage of interval keyword
| 1 DAY | INTERVAL 1 DAY | Hive 2.2.0 (HIVE-13557). | ||
Add timeunit aliases to aid portability / readability: SECONDS / MINUTES / HOURS / DAYS / WEEKS / MONTHS / YEARS | 2 SECONDS | 2 SECOND | Hive 2.2.0 (HIVE-13557). |
Decimals
Anchor | ||||
---|---|---|---|---|
|
Anchor | ||||
---|---|---|---|---|
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
CREATE TABLE foo ( a DECIMAL, -- Defaults to decimal(10,0) b DECIMAL(9, 7) ) |
For usage, see Floating Point Types 82706456 in the Literals section below.
...
Allowed Implicit Conversions
void | boolean | tinyint | smallint | int | bigint | float | double | decimal | string | varchar | timestamp | date | binary | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
void to | true | true | true | true | true | true | true | true | true | true | true | true | true | true |
boolean to | false | true | false | false | false | false | false | false | false | false | false | false | false | false |
tinyint to | false | false | true | true | true | true | true | true | true | true | true | false | false | false |
smallint to | false | false | false | true | true | true | true | true | true | true | true | false | false | false |
int to | false | false | false | false | true | true | true | true | true | true | true | false | false | false |
bigint to | false | false | false | false | false | true | true | true | true | true | true | false | false | false |
float to | false | false | false | false | false | false | true | true | true | true | true | false | false | false |
double to | false | false | false | false | false | false | false | true | true | true | true | false | false | false |
decimal to | false | false | false | false | false | false | false | false | true | true | true | false | false | false |
string to | false | false | false | false | false | false | false | true | true | true | true | false | false | false |
varchar to | false | false | false | false | false | false | false | true | true | true | true | false | false | false |
timestamp to | false | false | false | false | false | false | false | false | false | true | true | true | false | false |
date to | false | false | false | false | false | false | false | false | false | true | true | false | true | false |
binary to | false | false | false | false | false | false | false | false | false | false | false | false | false | true |