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