hive中的null和‘ ‘

string类型

在对string类型的字段进行查询过滤空值(这里包括NULL和’’)的时候我们一般以:

select name from student where name is not null and name != '';

要特别注意的是,我们在工作的过程当中,处理的字段可能会有很多空格存在,一般都有trim函数配合length函数去除空格来判断是否为空:

select length(trim(name)) from student;

int类型

在对int类型(包括其他数值类型)的字段进行查询过滤空值(这里包括NULL和’’)的时候我们一般以:

select age from student where age is not null;

用null还是’'更好呢?

Hive中默认将null存为\N,如果表中存在大量的NULL值,则在Hive的数据文件中会产生大量的\N数据,浪费存储空间,那我们可以将serialization.null.format设置为’’
(说明一下:在Hive中是通过serialization.null.format参数来保存和标识NULL,通过将表的该参数修改为NULL表示为空值)
那么,如何将底层NULL的存储格式修改为’’

//建表时使用
create table student2(
id int,
name string,
age int
)
row format delimited fields terminated by ','
NULL DEFINED AS '' --只要加这一句就可以
stored as textfile
location '/user/hive/warehouse/student';
// 修改已有的表
alter table student set serdeproperties('serialization.null.format' = '');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值