我有一个字段为“str”的表。当我跑的时候
select str from mytable where str is null
它打印空。但当我跑的时候:
INSERT OVERWRITE LOCAL DIRECTORY "/path/to/dir" select str from mytable where str is null;
中有'\n'个字符“/path/到/dir”我想知道在将结果写入本地文件时是否有方法将'\n'字符改为空字符串。
ewm0tg9j1#
@ashishsingh答案演示Hive
create table mytable (i int,j int,k int); insert into mytable values (1,2,null),(null,5,null),(7,null,9); select * from mytable ;
+-----------+-----------+-----------+ | mytable.i | mytable.j | mytable.k | +-----------+-----------+-----------+ | 1 | 2 | NULL | | NULL | 5 | NULL | | 7 | NULL | 9 | +-----------+-----------+-----------+
insert overwrite local directory "/tmp/mytable" row format delimited fields terminated by "," null defined as '' select * from mytable ;
猛击
cat /tmp/mytable/* 1,2, ,5, 7,,9
hfwmuf9z2#
是的,我需要零钱。您总是查询返回 null 结果如此直接 " " (empty string) 归档。
null
" " (empty string)
select if(str is null, " ", str) str from mytable where str is null
vuktfyat3#
使用this:-
INSERT OVERWRITE LOCAL DIRECTORY "/path/to/dir" ROW FORMAT DELIMITED FIELDS TERMINATED BY "\t" NULL DEFINED AS '' select str from mytable where str is null;
您可以删除 FIELDS TERMINATED BY "\t" 如果不需要
FIELDS TERMINATED BY "\t"
mkshixfv4#
好吧,你总是可以使用case语句,比如:
SELECT CASE WHEN str is null then '' ELSE str END;
请记住,可以使用以下表属性更改处理空字段的方式:“序列化.null.format”
4条答案
按热度按时间ewm0tg9j1#
@ashishsingh答案演示
Hive
猛击
hfwmuf9z2#
是的,我需要零钱。您总是查询返回
null
结果如此直接" " (empty string)
归档。vuktfyat3#
使用this:-
您可以删除
FIELDS TERMINATED BY "\t"
如果不需要mkshixfv4#
好吧,你总是可以使用case语句,比如:
请记住,可以使用以下表属性更改处理空字段的方式:
“序列化.null.format”