问题描述
我想用管道定界符将两个基于数组的列合并为1个单个输出列,并在输出中保留数组列表。是否可以在Hive或Spark sql中实现它? 请在输出中注意要使用管道delim实现的功能。
输入:
id val ph
1 [123,456] [789,987]
输出:
id Comb_col
1 [[123,456]|[789,987]]
解决方法
尝试一下:
SELECT id,CONCAT('[',val,'|',ph,']') as Comb_col
,
如果您想使用Hive,可以这样做:
from
(
from
your_table -- Change this with your table name
select
transform(id,ph) using '/bin/cat' as (id,ph)
) t
select
cast(id as int) as id,-- Assuming that your id column is int.
concat('[',']') as comb_col;