Created 07-09-2018 08:04 AM
I want to write hql that concatenates all columns in a table with comma separated.
ex)
target_table
col1 | col2 | col3 | col4 |
a01 | b01 | 100 | X1 |
a02 | b02 | 200 | X2 |
a03 | b03 | 300 | X3 |
Execute SELECT query
SELECT COL1 ,COL2 ,COL3 ,COL4 ,CONCAT???(T1.*) AS CONCAT_COL -- SQL for Concatenates all columns FROM target_table AS T1
Expected result
col1 | col2 | col3 | col4 | CONCAT_COL |
a01 | b01 | 100 | X1 | a01,b01,100,X1 |
a02 | b02 | 200 | X2 | a02,b02,100,X2 |
a03 | b03 | 300 | X3 | a03,b03,300,X3 |
Is there anyone has good idea for this ??
Thank you.
Created 07-09-2018 02:23 PM
I'm not sure what your original goal is - the following approach may help; or possibly not...
Beeline has some output format features which enables it to output the resultset in csv/tsv2 format. see: https://community.hortonworks.com/questions/25789/how-to-dump-the-output-from-beeline.html?childToVi...
I think with `concat_ws` you are very close; but I'm afraid its not possible to convert a struct into an array (or at least into a map - in which case you might be able to use `map_values` to obtain the array)
Created 11-12-2018 06:06 PM
You need to use CONCAT_WS (separator,col1,col2,...colX) :
select CONCAT_WS ('',c12,c13,c14,c15,c16) FROM your_table;
,Use CONCAT_WS , where you give the separator as 1st term and then the list of columns to concat :
select CONCAT_WS (' ',c12,c13,c14,c15,c16) from your_table) ;