hive表中字段顯示為NULL時,HDFS文件中存儲為\N


hive數據落地到hdfs,null會默認用'\N'存儲

解決方式1:利用命令(這個我沒起效果)

alter table adl_cici_test_fdt set serdeproperties('serialization.null.format' = '');

 解決方式2;建表時直接指定(兩種方式)

a、用語句
ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe’
with serdeproperties('serialization.null.format' = '')
實現,注意兩者必須一起使用,如
CREATETABLE hive_tb (idint,name STRING)
PARTITIONED BY (`day` string,`type` tinyint COMMENT'0 as bid, 1 as win, 2 as ck',`hour` tinyint)
ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe’
WITH SERDEPROPERTIES (‘field.delim’='/t’,‘escape.delim’='//’,serialization.null.format'='' )
STORED AS TEXTFILE;
b、或者通過 ROW FORMAT DELIMITED NULL DEFINED AS ''
CREATETABLE hive_tb (idint,name STRING)
PARTITIONED BY (`day` string,`type` tinyint COMMENT'0 as bid, 1 as win, 2 as ck',`hour` tinyint)
ROW FORMAT DELIMITED
NULL DEFINED AS ''
STORED AS TEXTFILE;
如:
create table vip_info( id string, mobile string)row format delimited fields terminated by '\t' NULL DEFINED AS '' stored as textfile;

 

解決方式3

insert overwrite directory 'hive_test/vip'
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'field.delim'='\t',
'serialization.format'= '',
'serialization.null.format'=''  
) STORED AS TEXTFILE
select * from user;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM