一、基本数据类型
类型 长度
tinyint 1b
smalint 2b
int 4b
bigint 8b
Boolean 布尔
float 单精度浮点数
double 双精度浮点数
string 字符序列
timestamp 整数,浮点数和字符串 (UTC)
binary 字节数组
注意:hive不支持“字符数组”。优化考虑因为定长的记录更容易进行建立索引,数据扫描。
hive 根据不同字段间的分隔符来对其进行判断。
类型转换:s是一个字符串类型,其值为数值 cast(s as int)。
二、集合数据类型
数据类型 描述 示例
struct 类似对象 struct(’小明‘,’小红‘)
map 一组键值对 map(’key‘,’value‘,’key1‘,’value1‘)
array 数组是一组相同类型和名称的变量的集合 array(’小明‘,’小红‘)
三、文本文件数据编码
分隔符 描述
\n 换行符
^A 分隔列
^B 分隔array或struct
^C 分隔MAP
create table tablename( first int, second int, third array<string>, fouth map<string,string>, five struct<one:string,two:string> ) row format delimited fields terminated by '\001' collection items terminate by '\002' map keys terminated by '\003' lines terminated by '\n' stored as textfile;
字符\001是八进制A
字符\002是八进制B
字符\003是八进制C
定义一个表数据用逗号进行分隔的表
create table test ( first int, second int, third int ) row format delimited fields terminated by ',';
四、读时模式
如果加载数据少于对应的模式时,那么默认null进行处理。