hive null and empty string--- 系列(三)-- SeqFile

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

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

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

RCFile

(一)原始状态

create table test.seqfile (id int ,name string)   STORED AS SequenceFile;

show create table test.seqfile;

CREATE TABLE `test.seqfile`(
  `id` int, 
  `name` string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.SequenceFileInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat'
LOCATION
  'hdfs://devCluster/user/hive/warehouse/test.db/seqfile'
TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}', 
  'numFiles'='0', 
  'numRows'='0', 
  'rawDataSize'='0', 
  'totalSize'='0', 
  'transient_lastDdlTime'='1623401838')

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

看一下HDFS中存储的数据,按行存储,null 为 \N

(二)使用参数

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

create table test.seqfile_par (id int ,name string)   STORED AS SequenceFile;

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

show create table test.seqfile_par;

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

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

id=2 时,name 从 empty string 变成 null,选取空值时,仍然能选择出来

看一下HDFS中存储的数据,按行存储,null 为 empty string

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值