hive null and empty string--- 系列(四)-- ORCFile

目的:预将hive中 null 与 empty string 统一,便捷后续开发

问题:orc 文件 使用  SET SERDEPROPERTIES('serialization.null.format' = '') 失效

解决方案:探索 null 再各个file_format 的存储方式

ORCFile
(一)原始状态

create table test.orcfile (id int ,name string)   STORED AS orc;


show create table test.orcfile;

CREATE TABLE `test.orcfile`(
  `id` int, 
  `name` string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.orc.OrcSerde' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
  'hdfs://devCluster/user/hive/warehouse/test.db/orcfile'
TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}', 
  'numFiles'='0', 
  'numRows'='0', 
  'rawDataSize'='0', 
  'totalSize'='0', 
  'transient_lastDdlTime'='1623402600')

插入数据,查看 null and empty string 存储形式 

insert overwrite table test.orcfile values ('1','ddd');
insert into table test.orcfile values (2,'');
insert into table test.orcfile values (3,null);
insert into table test.orcfile values (4,'\N');
insert into table test.orcfile values (5,'\\N');
insert into table test.orcfile values ('qwe','ppp');
insert into table test.orcfile values ('sdd','ooo');

SELECT
*
from 
test.orcfile
;

 


发现,id 的数据类型是 int ,插入数值的string类型成功,但是插入字符串后其值变成null。但是 插入“\\N” 仍被标记成null了。

(二)使用参数

使用  SET SERDEPROPERTIES('serialization.null.format' = '')参数 

create table test.orcfile_par (id int ,name string)   STORED AS orc;

alter table test.orcfile_par SET SERDEPROPERTIES('serialization.null.format' = '');

show create table test.orcfile_par;

CREATE TABLE `test.orcfile_par`(
  `id` int, 
  `name` string)
ROW FORMAT DELIMITED 
  NULL DEFINED AS '' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
  'hdfs://devCluster/user/hive/warehouse/test.db/orcfile_par'
TBLPROPERTIES (
  'last_modified_by'='qll', 
  'last_modified_time'='1623402986', 
  'numFiles'='0', 
  'numRows'='0', 
  'rawDataSize'='0', 
  'totalSize'='0', 
  'transient_lastDdlTime'='1623402986')


插入数据,查看 null and empty string 存储形式

insert overwrite table test.orcfile_par values ('1','ddd');
insert into table test.orcfile_par values (2,'');
insert into table test.orcfile_par values (3,null);
insert into table test.orcfile_par values (4,'\N');
insert into table test.orcfile_par values (5,'\\N');
insert into table test.orcfile_par values ('qwe','ppp');
insert into table test.orcfile_par values ('sdd','ooo');

SELECT
*
from 
test.orcfile_par
;


发现,id 的数据类型是 int ,插入数值的string类型成功,但是插入字符串后其值变成null。空值并未和 empty string 统一,即SET SERDEPROPERTIES('serialization.null.format' = '') 并未起作用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值