Search code examples
apache-sparkhadoophivehiveql

string concat operator(||) throwing error in hive


I am trying to concat string columns in table with concat operator || and throwing error.

Here is the query: select "Bob"||'~'||"glad" from table

its throwing error as : ParseException - cannpt recognize input near '|' '"~"' '|' in expression specification

its works with concat function but not with concat operator.

select concat("bob","~","glad") from table - its working

I am using hive version 2.1 and could anyone tell me why this operator not working?

Thanks,Babu


Solution

  • Hive doesnt support concat operator ||, its oracle syntax. Please use concat function to concat multiple values. You can use concat_ws to concat with a delimiter.
    concat

    select concat ('this','~','is','~','hello','~','world');
    Output : this~is~hello~world
    select concat_ws ('~','hello','world','is','not','enough');
    Output : hello~world~is~not~enough