Hive:null

Hive:null

  1. 字符串为'\N'(默认)
  2. 字符串为'NULL'
  3. 文本中的内容与hive表定义的字段类型不相符

解决方式

解决字符串为'\N'的字符串

定义表时,指定 NULL为指定的标识符

create table if not exists xxxx(
id varchar(32) primary key,
age int ,
name varchar(32)
) row format delimited
fields terminated by ','
NULL defined as ''
stored as textfile;

-- 或者
create table if not exists xxxx(
id varchar(32) primary key,
xxxx
) row format delimited
fields terminated by ','
with SERDEPROPERTIES('serialization.null.format'='')
stored as textfile;

-- 或者
alter table xxxx set serdeproperties('serialization.null.format'='');

数据加载到表中的方式

load data [local] inpath '/..../...'  [overwrite] into table tableName

会把文件原样移动到对应的表中

insert into xxxx select * from tableName

会做一些转换(如果xxxx定义NULL 为空字符串时)

1.如果tableName中因为字段与表定义时的字段类型不一致时,会转换成空字符串保存在xxxx表

2.如果tableName定义空字符中为'\N'时,也会转换成空字符串保存在xxxx表

3.如果字段为字符串"NULL"时,会直接把“NULL"字符串写入到tableName表中

关于NULL的查询

条件为

where field is null  -- 指示这个字符保存为指定的空格式(这个可以节约一些存储空间)

where field = 'NULL' -- 这个字符存储了字符"NULL“

 

Handling of NULL Values

没有值代表值为NULL。为了在导入数据时,使用NULL字段,需要参考表使用的序列与反序列类型。默认情况下,Text 格式使用

LazySimpleSerDe,它把字符串‘\N'解释为NULL。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值