示例页面

null(空值)与空字符的处理

string类型的' '(空字符),hive底层中存储为' '

int/string类型的null,底层存储为\N,尽管这样做会占据较多资源,但是却方便了插入空值数据的操作(提前占位)

对于null的提取:is null // is not null // coalesce(null,'')

对于' '的提取:

1)修改已有表:alter table test_01 set serdeproperties('serialization.null.format'='')在底层存储中,使' '和null等价,null存储展示为' ',查询结果展示为null,这时同样用is null // is not null查询

2)建表时指定:

    eg1.

       ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'

       with serdeproperties('serialization.null.format' = '')

    eg2.

       ROW FORMAT DELIMITED NULL DEFINED AS ''

3)个人认为这是最为方便的

       如存在以下数据,第一行无数据的数据类型是string的' '

        通过下述操作,即可剔除' '的行
select col1,col2,col3,col4
from table_name
where col2>'0'  ##(只要不是=' ',>' '也行,提示:与ascii码有关)

参考来源:

HIVE踩坑——NULL和空字符串处理

hive中的NULL(hive空值处理)

posted @ 2019-09-26 11:18  没有风格的Wang  阅读(1842)  评论(0编辑  收藏  举报