Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table mytable (id int,A array<string>,B array<string>);
- insert into table mytable
- select 1,array('P908','S57','A65'),array('P908','S57')
- union all select 2,array('P908','S57','A65'),array('P9','S5777')
- ;
- select * from mytable;
- +------------+----------------------+----------------+
- | mytable.id | mytable.a | mytable.b |
- +------------+----------------------+----------------+
- | 1 | ["P908","S57","A65"] | ["P908","S57"] |
- | 2 | ["P908","S57","A65"] | ["P9","S5777"] |
- +------------+----------------------+----------------+
- select id
- ,concat(',',concat_ws(',',A),',') as left_side_of_regexp
- ,concat(',(',concat_ws('|',B),'),') as right_side_of_regexp
- ,concat(',',concat_ws(',',A),',') regexp
- concat(',(',concat_ws('|',B),'),') as are_shared_elements
- from mytable
- ;
- +----+---------------------+----------------------+---------------------+
- | id | left_side_of_regexp | right_side_of_regexp | are_shared_elements |
- +----+---------------------+----------------------+---------------------+
- | 1 | ,P908,S57,A65, | ,(P908|S57), | true |
- | 2 | ,P908,S57,A65, | ,(P9|S5777), | false |
- +----+---------------------+----------------------+---------------------+
- select collect_set (array_contains (col1 , r.tab2) )
- from table1 ,
- (select exp1 as tab2
- from (table2 t2 lateral view explode(col2) exploded_table as exp1 ) ) r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement