Hive 数据类型与文件格式

一、基本数据类型

1、基本数据类型

Tinyint  1byte有符号整数  比如20

Smalint 2byte有符号整数 比如20

Int          4byte有符号整数 比如20

Bigint     8byte有符号整数 比如20

Boolean  布尔类型,true或者false

Float        单精度浮点类型  3.14159265358

Double     双精度灰暗类型  3.14159265358

String       字符序列,可以指定字符集    比如'now is the time'

Timestamp 整数,浮点数或者字符串    

binary       字节数组 

2、隐式转换

比如float与double作比较,Hive会隐士地将类型转换为零个整型类型中值较大的那个类型。

3、数据类型转换

...cast(s AS INT)...;

二、集合数据类型

 三、文本文件数据编码

1、默认分2、指定分隔符

create table employees(

name string,

salary float,

subordinates array<string>,

deductions map<string,float>,

address struct<street:string,city:string,state:string,zip:int>

)

row format delimited

fields terminated by '01'

collection items terminated by '02'

map keys terminated by '03'

lines terminated by ' '

stored as textfile;

row format delimited必须写在其他字句之前

1)'01'是^A的八进制数----row format delimited fields terminated by '01' 字句表明将使用^A字符作为列分隔符

2)'02'是^B的八进制数----row format delimited collection items terminated by '02' 表明将使用^B作为集合元素间的分隔符

3)'03'是^C的八进制数----row format delimited map keys terminated by '03' 表明将使用^C作为map的键值之间的分隔符

4)lines terminated by ' ' 与stored as textfile不需要row format delimited关键字

目前Hive仅支持' ',行与行之间的分隔符

四、读时模式

1、写时模式

数据在写入数据库时对模式进行检查

2、读时模式

Hive不会再数据加载时进行验证,而是在查询时进行,也就是读时模式

3、Hive发现模式和文件内容不匹配将会怎样

Hive让然可以读取这些数据。

如果每行记录中的字段个数少于对应的模式中定义的字段个数,那么用户将会看到查询结果中有很多null值。

如果某些字段是数值型,但是Hive在读取时发现存在非数值型的字符串的话,那么对于哪些字段将会返回null值。

除此之外的其他情况,hive都极力尝试尽可能地将各种错误恢复过来。

原文地址:https://www.cnblogs.com/xibuhaohao/p/11811751.html