explode_split

description

表函数,需配合 Lateral View 使用。

将一个字符串按指定的分隔符分割成多个子串。

语法:

  1. explode_split(str, delimiter)

example

原表数据:

  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. +------+------+
  7. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 2 order by k1, e1;
  8. Empty set
  9. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 3 order by k1, e1;
  10. +------+------+
  11. | k1 | e1 |
  12. +------+------+
  13. | 3 | |
  14. | 3 | |
  15. +------+------+
  16. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 4 order by k1, e1;
  17. +------+------+
  18. | k1 | e1 |
  19. +------+------+
  20. | 4 | 1 |
  21. +------+------+
  22. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 5 order by k1, e1;
  23. +------+------+
  24. | k1 | e1 |
  25. +------+------+
  26. | 5 | 1 |
  27. | 5 | 2 |
  28. | 5 | 3 |
  29. +------+------+
  30. mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 6 order by k1, e1;
  31. +------+------+
  32. | k1 | e1 |
  33. +------+------+
  34. | 6 | b |
  35. | 6 | c |
  36. | 6 | a |
  37. +------+------+

keywords

  1. explode_split