Concatenated multiple lines with a delimiter in the hive

I need to specify the string values โ€‹โ€‹of a string with the character '~' as a separator. I have the following data:

enter image description here

I need to execute the "Comment" column for each "id" in ascending order of "row_id" with "~" as a separator.

The expected result is as follows:

enter image description here

GROUP_CONCAT is not an option since it is not recognized in my version of Hive. I can use collect_set or collect_list, but I will not insert a separator between them.

Is there any work?

+6
source share
1 answer

collect_list , .
concat_ws.


.

select      id
           ,concat_ws('~',collect_list(comment)) as comments

from        mytable 

group by    id
;

+----+-------------+
| id |  comments   |
+----+-------------+
|  1 | ABC~PRQ~XYZ |
|  2 | LMN~OPQ     |
+----+-------------+
+6

Source: https://habr.com/ru/post/1015931/


All Articles