Hive 行转列,列传行 - Impala 暂不支持
注:Impala 不支持 lateral view explode?
一、行轉列?(對某列拆分,一列拆多行)
使用函數:lateral view explode(split(column, ',')) num
eg: 如表:t_row_to_column_tmp 數據如下,對tag列進行拆分
SQL代碼:
select id,tag,tag_new
? from t_row_to_column_tmp
lateral view explode(split(tag, ',')) num as tag_new
where id=212022894;
?
二、列轉行?(根據主鍵,進行多行合并一列)
使用函數:concat_ws(',',collect_set(column)) ?
說明:collect_list 不去重,collect_set 去重。 column 的數據類型要求是 string
eg:如表:t_column_to_row ,根據id,對tag_new 進行合并
?
SQL代碼1:
select id,
? ? ? ? ?concat_ws(',',collect_set(tag_new)) as tag_col
?from t_column_to_row
group by id;
?
SQL代碼2:
select id,
? ? ? ? ?concat_ws(',',collect_list(tag_new)) as tag_col
?from t_column_to_row
group by id;
?
參考:https://www.cnblogs.com/kimbo/p/6208973.html
總結
以上是生活随笔為你收集整理的Hive 行转列,列传行 - Impala 暂不支持的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: phoenix创建索引报错“ Mutab
- 下一篇: C++中的Dll内存问题