Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive String operator concatenate by || double pipe

Tags:

hive

hiveql

Language manual of Hive claims that double pipe string concatenation is supported, however I am unable to use this feature in my current version of HIVE 1.2.1000.2.4.3.6-2

hive> select 'a'||'b';
NoViableAltException(5@[323:1: atomExpression : ( ( KW_NULL )=> KW_NULL -> TOK_NULL | ( constant )=> constant | castExpression | caseExpression | whenExpression | ( functionName LPAREN )=> function | tableOrColumn | LPAREN ! expression RPAREN !);])

I was trying to find a version which starts to support that, but without any luck :-(

I know that I can use build in function concat to do the same thing, but I am rewriting bunch of Oracle views to Hive and I don't want to change things which can stay the same if possible.

like image 343
Martin Avatar asked Jul 12 '17 11:07

Martin


People also ask

How do I concatenate two strings in hive?

CONCAT_WS( string delimiter, string str1, string str2… ) The CONCAT_WS function is similar to the CONCAT function. Here you can also provide the delimiter, which can be used in between the strings to concat.

What is || in hive?

Description. A || B. strings. Concatenates the operands - shorthand for concat(A,B) . Supported as of Hive 2.2.

How do you concatenate 2 strings?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.

How do I concatenate two column values in hive?

Use concat_ws function to concatenate values with ^ as a delimiter. If columns are not string, wrap them with cast as string using shell, this will allow concat_ws work with strings and not-string columns. Use new variable to pass to hive as in the previous example.


1 Answers

Hive 2.2.0
The documentation is very clear about that

enter image description here https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringOperators

like image 198
David דודו Markovitz Avatar answered Nov 07 '22 18:11

David דודו Markovitz