create temporary macro empty2null(s string)
case when s='' then null
when s is null then 'NULL'
else s
end;
create temporary macro NULL2empty (s string)
case when s='NULL' then null
when s is null then ''
else s
end;
select NULL2empty(coalesce(empty2null(''),empty2null(5)));
hive> create temporary macro empty2null(s string)
> case when s='' then null
> when s is null then 'NULL'
> else s
> end;
OK
Time taken: 0.97 seconds
hive>
> create temporary macro NULL2empty (s string)
> case when s='NULL' then null
> when s is null then ''
> else s
> end;
OK
Time taken: 0.02 seconds
hive>
> select NULL2empty(coalesce(empty2null(''),empty2null(5)));
OK
5
Time taken: 7.08 seconds, Fetched: 1 row(s)
hive> select NULL2empty(coalesce(empty2null(''),empty2null('')));
OK
Time taken: 3.96 seconds, Fetched: 1 row(s)
hive> select NULL2empty(coalesce(empty2null(''),empty2null(null)));
OK
NULL
Time taken: 0.952 seconds, Fetched: 1 row(s)
hive> select NULL2empty(coalesce(empty2null(5),empty2null('')));
OK
5
Time taken: 0.067 seconds, Fetched: 1 row(s)
1条答案
按热度按时间w8rqjzmb1#
变换
NULL
把它们串起来'NULL'
,空到NULL
使用coalesce
,然后转换回。像这样:唯一不方便的是,您必须将每一列都 Package 到
empty2null()
,除了常量5
,只是检查一下测验: