impala,hive行转列

本文探讨了如何在Hive和Impala中进行行转列的操作。在Hive中,利用collect_set()和concat_ws()可以实现,但若要移除重复元素可能需要自定义UDF。而Impala提供了group_concat()函数,用于将不同行的值连接成字符串。文章还提到了其他数据库如MySQL、Presto的相关操作,并提到了lateral view和explode()等Hive中的功能。
摘要由CSDN通过智能技术生成
Hive

For Hive, I use collect_set() + concat_ws() from https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF.
But if you want to remove duplicated elements, write your own UDF should be the only choice till now.

Impala

Impala also has a group_concat() but different from mysql

group_concat(string s [, string sep])
Purpose: Returns a single string representing the argument value concatenated together for each row of the result set. If the optional separator string is specified, the separator is added between each pair of concatenated values.
Return type: string

Usage notes: concat() and concat_ws() are appropriate for concatenating the values of multiple columns within the same row, while group_concat() joins together values from different rows.

By default, returns a single string covering the whole result set. To include other columns or values in the result set, or to produce multiple concatenated strings for subsets of rows, include a GROUP BY clause in the query.

group_concat(string s [, string sep]) 和分组函数配合使用,group_concat(字段, 分隔符) ,下面例子:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值