explode_split
description
Table functions must be used in conjunction with Lateral View.
Split a string into multiple substrings according to the specified delimiter.
grammar:
1. explode_split(str, delimiter)
example
Original table data:
1. mysql> select * from example1 order by k1;
2. +------+---------+
3. | k1 | k2 |
4. +------+---------+
5. | 1 | |
6. | 2 | NULL |
7. | 3 | , |
8. | 4 | 1 |
9. | 5 | 1,2,3 |
10. | 6 | a, b, c |
11. +------+---------+
Lateral View:
1. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 1 order by k1, e1;
2. +------+------+
3. | k1 | e1 |
4. +------+------+
5. | 1 | |
6. +------+------+
8. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 2 order by k1, e1;
9. +------+------+
10. | k1 | e1 |
11. +------+------+
12. | 2 | NULL |
13. +------+------+
15. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 3 order by k1, e1;
16. +------+------+
17. | k1 | e1 |
18. +------+------+
19. | 3 | |
20. | 3 | |
21. +------+------+
23. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 4 order by k1, e1;
24. +------+------+
25. | k1 | e1 |
26. +------+------+
27. | 4 | 1 |
28. +------+------+
30. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 5 order by k1, e1;
31. +------+------+
32. | k1 | e1 |
33. +------+------+
34. | 5 | 1 |
35. | 5 | 2 |
36. | 5 | 3 |
37. +------+------+
39. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 6 order by k1, e1;
40. +------+------+
41. | k1 | e1 |
42. +------+------+
43. | 6 | b |
44. | 6 | c |
45. | 6 | a |
46. +------+------+
keywords
explode,split,explode_split
