The CONCAT_WS function in Apache Hive incorporates two or more strings into a single string with the specified delimiter.
SELECT fname, lname, CONCAT_WS(‘ ‘, fname, lname) FROM firstlastnames;
However, this function can be used to combine row values into a single string. Using CONCAT WS along with COLLECT SET we can join the row values into a single string. This functionality would be equivalent to GROUP CONCAT in MySQL and Apache Impala, STRING AGG in Microsoft SQL Server and LISTAGG in Oracle SQL.
Let’s see how we can do that.
Here is my test-data.
SELECT Product, CONCAT_WS(‘,’, COLLECT_SET(CAST(sales AS STRING)))
GROUP BY Product
Hope you liked this post.
Please click on the follow button to receive notifications on latest posts.