explode

description

Table functions must be used in conjunction with Lateral View.

explode array column to rows. explode_outer will return NULL, while array is NULL or empty. explode and explode_outer both keep the nested NULL elements of array.

syntax

  1. explode(expr)
  2. explode_outer(expr)

example

  1. mysql> select e1 from (select 1 k1) as t lateral view explode([1,2,3]) tmp1 as e1;
  2. +------+
  3. | e1 |
  4. +------+
  5. | 1 |
  6. | 2 |
  7. | 3 |
  8. +------+
  9. mysql> select e1 from (select 1 k1) as t lateral view explode_outer(null) tmp1 as e1;
  10. +------+
  11. | e1 |
  12. +------+
  13. | NULL |
  14. +------+
  15. mysql> select e1 from (select 1 k1) as t lateral view explode([]) tmp1 as e1;
  16. Empty set (0.010 sec)
  17. mysql> select e1 from (select 1 k1) as t lateral view explode([null,1,null]) tmp1 as e1;
  18. +------+
  19. | e1 |
  20. +------+
  21. | NULL |
  22. | 1 |
  23. | NULL |
  24. +------+
  25. mysql> select e1 from (select 1 k1) as t lateral view explode_outer([null,1,null]) tmp1 as e1;
  26. +------+
  27. | e1 |
  28. +------+
  29. | NULL |
  30. | 1 |
  31. | NULL |
  32. +------+

keywords

EXPLODE,EXPLODE_OUTER,ARRAY