This is one possible way, there could be better ones
select * from tbl1;
+----------+------------+--+
| tbl1.id | tbl1.val |
+----------+------------+--+
| abc | {0|1|0} |
| abc | {0|1|1} |
| abc | {1|0|1|1} |
+----------+------------+--+
Write it somewhere without {}
insert overwrite directory '/user/cloudera/tbl2'
row format delimited fields terminated by ','
select id, substr(val,2,length(val)-2) as val2 from tbl1
Create a table to use it
create external table tbl3(id string, val array<int>)
row format delimited
fields terminated by ','
collection items terminated by '|'
location '/user/cloudera/tbl2'
+----------+------------+--+
| tbl3.id | tbl3.val |
+----------+------------+--+
| abc | [0,1,0] |
| abc | [0,1,1] |
| abc | [1,0,1,1] |
+----------+------------+--+
Use posexplode
select id, collect_list(val)
from (
select id, sum(c) as val
from (
select id, i, c from tbl3
lateral view posexplode(val) v1 as i, c
) tbl
group by id, i
) tbl2
group by id
the result
+------+------------+--+
| id | _c1 |
+------+------------+--+
| abc | [1,2,2,1] |
+------+------------+--+