Hive concat concat_ws 拼接空字符串的坑

concat() :如果存在空,返回空:

hive> select concat('cd','1');
OK
cd1
Time taken: 0.461 seconds, Fetched: 1 row(s)
hive> select concat('cd',1);
OK
cd1
Time taken: 0.066 seconds, Fetched: 1 row(s)
hive> select concat('cd',null);
OK
NULL
Time taken: 0.053 seconds, Fetched: 1 row(s)
hive> select concat('null','cd');
OK
nullcd
Time taken: 0.06 seconds, Fetched: 1 row(s)
hive> select concat(null,'cd');
OK
NULL
Time taken: 0.056 seconds, Fetched: 1 row(s)
hive>
hive> select concat(null,'cd','cd');
OK
NULL
Time taken: 0.052 seconds, Fetched: 1 row(s)
hive> select concat('12','cd','cd');
OK
12cdcd
Time taken: 0.051 seconds, Fetched: 1 row(s)
hive> select concat('12',null,'cd');
OK
NULL
Time taken: 0.064 seconds, Fetched: 1 row(s)
hive> select concat('12','cd',null);
OK
NULL
Time taken: 0.047 seconds, Fetched: 1 row(s)
hive>

 

concat_ws:如果存在空,返回非空的拼接:

hive> select concat_ws('_','a','c','v','d');
OK
a_c_v_d
Time taken: 0.06 seconds, Fetched: 1 row(s)
hive> select concat_ws('_',null,'c','v','d');
OK
c_v_d
Time taken: 0.047 seconds, Fetched: 1 row(s)
hive> select concat_ws('_',null,'c',null,'d');
OK
c_d
Time taken: 0.053 seconds, Fetched: 1 row(s)
hive> select concat_ws(null,'a','c','v','d');
OK
NULL
Time taken: 0.055 seconds, Fetched: 1 row(s)
hive>

hive> select concat_ws('_',null,'c',null);
OK
c
Time taken: 0.072 seconds, Fetched: 1 row(s)
hive> select concat_ws('_',null,null,null);
OK

Time taken: 0.049 seconds, Fetched: 1 row(s)
hive>

 

Hive 2.0.0-SNAPSHOT

 

 

更多企业内的技术应用和使用技巧,请移步至我的公众号【程序员实用技能】

图片

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页