Hive:null
- 字符串为'\N'(默认)
- 字符串为'NULL'
- 文本中的内容与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。