...
The DECIMAL
type in Hive is based on Java's BigDecimal which is used for representing immutable arbitrary precision decimal numbers in Java. All regular number operations (e.g. +, -, *, /) and relevant UDFs (e.g. Floor, Ceil, Round, and many more) handle decimal types. You can cast to/from decimal types like you would do with other numeric types. The persistence format of the decimal type supports both scientific and non-scientific notation. Therefore, regardless of whether your dataset contains data like 1E+44 (scientific notation) or 4004 (non-scientific notation) or a combination of both, DECIMAL
can be used for it.
- Hive 0.11 and 0.12 have the precision of the
DECIMAL
type fixed and limited to 38 digits. - As of Hive 0.13 users can specify scale and precision when creating tables with the
DECIMAL
datatype using aDECIMAL(precision, scale)
syntax. If scale is not specified, it defaults to 0 (no fractional digits). If no precision is specified, it defaults to 10.
Code Block | ||||
---|---|---|---|---|
| ||||
CREATE TABLE foo ( a DECIMAL, -- Defaults to decimal(10,0) b DECIMAL(9, 7) ) |
For usage, see Floating Point Types in the Literals section below.
Anchor | ||||
---|---|---|---|---|
|
Decimal Literals
Integral literals larger than BIGINT must be handled with Decimal(38,0). The Postfix BD is required. Example:
...