我想使用 hql 将以下列从列表转换为数组
我还想将它从数组转换为列表
最佳答案
数组列出演示:
with mytable as (
select stack (2,
array(10,20),
array(30,40,50)
) as myarray
)
select myarray, concat('[',concat_ws(':',collect_list(string(element))),']') as list
from mytable
lateral view explode(myarray) e as element
group by myarray;
结果:
myarray list
[10,20] [10:20]
[30,40,50] [30:40:50]
列表到数组演示:
with mytable as (
select stack (2,
'[10:20]',
'[30:40:50]'
) as list
)
select list, collect_list(int(element)) myarray
from mytable
lateral view explode (split(regexp_replace(list,'\\[|\\]',''),':')) e as element
group by list;
结果:
list myarray
[30:40:50] [30,40,50]
[10:20] [10,20]
如果您同意array<string>
,那么转换就简单多了:
with mytable as (
select stack (2,
'[10:20]',
'[30:40:50]'
) as list
)
select list, split(regexp_replace(list,'\\[|\\]',''),':') myarray
from mytable;
结果:
list myarray
[10:20] ["10","20"]
[30:40:50] ["30","40","50"]
关于sql - 使用 hql 将列从列表转换为数组,以及将数组转换为 hive 中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65694067/