目的:预将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