简体   繁体   English

如何在Hive中用2个定界符连接列

[英]How to concat columns with 2 delimiters in hive

How to concat columns with 2 delimiters in hive. 如何在配置单元中用2个定界符连接列。 Please find below the input columns. 请在输入栏下方找到。

column1 column2 column3 column4 column5 column6 column7 column8
1        abc    dfe     ghi     jkl     mno     pqr     1
2        abc    dfe     ghi     jkl     mno     pqr     1

Required output concatenated string grouped by colum8 ie, value 1. 必需的输出串联字符串,按colum8分组,即值1。

1:abc:dfe:ghi:jkl-mno:pqr,2:abc:dfe:ghi:jkl-mno:pqr

can someone help me. 有人能帮我吗。

Can you try this? 你可以试试这个吗?
First, create new columns concatenating each columns for every row then collect the concantenated columns (using collect_list) into one column by grouping them based on column8 then concatenate it (using concat_ws): 首先,创建新的列,将每一行的每一列连接在一起,然后通过基于column8将它们合并成一列,然后将其合并在一起(使用concat_ws):

select concat_ws(',',
                 collect_list(concat(column1, ':', column2, ':', column3, ':', column4,':', column5, '-', column6, ':', column7
                                    )
                             )
                ) as output
from your_table
group by column8;

I would write this as: 我可以这样写:

select concat_ws(',',
                 collect_list(concat_ws(':', column1, column2, column3, column4, column5 || '-' || column6, column7)
                             )
                ) as output
from your_table
group by column8;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM