Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. create table mytable (id int,A array<string>,B array<string>);
  2.  
  3. insert into table mytable
  4.  
  5. select 1,array('P908','S57','A65'),array('P908','S57')
  6. union all select 2,array('P908','S57','A65'),array('P9','S5777')
  7. ;
  8.  
  9. select * from mytable;
  10.  
  11. +------------+----------------------+----------------+
  12. | mytable.id | mytable.a | mytable.b |
  13. +------------+----------------------+----------------+
  14. | 1 | ["P908","S57","A65"] | ["P908","S57"] |
  15. | 2 | ["P908","S57","A65"] | ["P9","S5777"] |
  16. +------------+----------------------+----------------+
  17.  
  18. select id
  19. ,concat(',',concat_ws(',',A),',') as left_side_of_regexp
  20. ,concat(',(',concat_ws('|',B),'),') as right_side_of_regexp
  21.  
  22. ,concat(',',concat_ws(',',A),',') regexp
  23. concat(',(',concat_ws('|',B),'),') as are_shared_elements
  24.  
  25. from mytable
  26. ;
  27.  
  28. +----+---------------------+----------------------+---------------------+
  29. | id | left_side_of_regexp | right_side_of_regexp | are_shared_elements |
  30. +----+---------------------+----------------------+---------------------+
  31. | 1 | ,P908,S57,A65, | ,(P908|S57), | true |
  32. | 2 | ,P908,S57,A65, | ,(P9|S5777), | false |
  33. +----+---------------------+----------------------+---------------------+
  34.  
  35. select collect_set (array_contains (col1 , r.tab2) )
  36. from table1 ,
  37. (select exp1 as tab2
  38. from (table2 t2 lateral view explode(col2) exploded_table as exp1 ) ) r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement