We will see the Basic data types in Hive.
Numeric Types
TINYINT
1 byte signed integer. Values range -128 to 127
SMALLINT
2 byte signed integer. Values range -32,768 to 32,767
INT
4 byte signed integer. Values range -2,147,483,648 to 2,147,483,647
BIGINT
8 byte signed integer. Values range -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
Decimal is used to represent arbitrary precision decimal numbers. We can provide the precision and scale for the Decimal numbers.
Precision- Total number of digits.
Scale – Number of digits in the fractional part i.e digits after ‘.’.
String Types
STRING
A variable length character string.
VARCHAR
A variable length character string for which we need to specify the maximum number of characters allowed(1-65355). If string value have more characters than specified, then the string value is truncated. If the string value have less characters then only those characters are stored.
CHAR
A fixed length character string(1-255). If string value have more characters than specified, then the string value is truncated. If the string value have less characters then the string is padded with spaces.
Date Types
Date
Date can store year/month/day component of a Date. Date do not store time components. Format YYYY-MM-DD.
Timestamp
Timestamp stores the timestamp values in the format ‘YYYY-MM-DD HH:MM:SS.fffffffff’.
Others
Boolean
Boolean can have literal values TRUE or FALSE. Mixed case is allowed whicle using boolean literals.
We can cast TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, or DECIMAL to BOOLEAN by using CAST() function. A value of 0 is considered as false, and any non-zero value is considered as true.
We cannot cast a STRING value to BOOLEAN. But we can cast a BOOLEAN value to STRING, returning ‘1’ for true and ‘0’ for false.