本文中介绍了hive中数据类型知识点,包含:
类型 | 说明 |
|---|---|
TINYINT | 1个字节,-128~127 |
SMALLINT | 2个字节,-32768~32767 |
INT/INTEGER | 4个字节 |
BIGINT | 8个字节 |
FLOAT | 4个字节单精度 |
DOUBLE | 8字节双精度 |
DECIMAL | 38位小数精度,支持科学计数法DECIMAL(9,7) DECIMAL(precision, scale) decimal(10,0) |
它支持传统的UNIX时间戳可选纳秒的精度。它支持的java.sql.Timestamp格式YYYY-MM-DD HH:MM:SS.fffffffff和格式YYYY-MM-DD HH:MM:ss.ffffffffff。
DATE值在年/月/日的格式形式描述 NaN
create table bigdata(name char(10))Syntax: ARRAY<data_type>
Array("hadoop", "hive", "spark")
array[1]="hive"Syntax: MAP<primitive_type, data_type>
Map(1:"hadoop", 2:"hive")
map[1]="hadoop"Syntax: STRUCT<col_name : data_type [COMMENT col_comment], …>
Struct(a:5, b:"hive")
struct.a=5UNIONTYPE<int, double, array<string>, struct<a:int,b:string>>
{0:1}
{1:2.0}
{2:["three","four"]}
{3:{"a":4,"b":"five"}}
{2:["six","seven"]}
{3:{"a":8,"b":"eight"}}
{0:8}create table complex(
col1 array<int>,
col2 map<string,int>,
col3 struct<a:string,b:int>,
col4 uniontype<string,int>
)hive中的数据类型转换也分为隐式类型转换和显式类型转换
第一行的名称为对应第一列的名称缩写
float、string都可以隐式转成double类型cast(value as type)# demo
SELECT name,salary
FROM employee
WHERE cast(salary as float) < 100.0;如果salary是不能转换成float,这时``cast将会返回NULL`
int类型,内部操作是通过round()或者floor()函数来实现的,而不是通过castcast()可以进行嵌套操作SELECT (cast(cast(a as string) as double)) from src; # 先转成string,再转成doubleDate类型的数据,只能在Date、Timestamp以及String之间进行转换