array_sortby

array_reverse_split

description

Syntax

  1. ARRAY<ARRAY<T>> array_reverse_split(ARRAY<T> arg, Array<Boolean> cond)
  2. ARRAY<ARRAY<T>> array_reverse_split(lambda, ARRAY<T0> arg0...)
  1. pass in two ARRAY of equal length, the second of which is an Array<Boolean>, and split the arg according to the split point to the right of the position in the cond that is true.
  2. Higher-order functions, passed a lambda expression and at least one ARRAY arg0, split arg0 by the right-hand side of the true position in the cond of the Array<Boolean> result of the operation on the lambda expression.

example

  1. mysql> select array_reverse_split([1,2,3,4,5], [1,0,1,0,0]);
  2. +-------------------------------------------------------------------------------+
  3. | array_reverse_split([1, 2, 3, 4, 5], cast([1, 0, 1, 0, 0] as ARRAY<BOOLEAN>)) |
  4. +-------------------------------------------------------------------------------+
  5. | [[1], [2, 3], [4, 5]] |
  6. +-------------------------------------------------------------------------------+
  7. 1 row in set (0.12 sec)
  8. mysql> select array_reverse_split((x,y)->y, [1,2,3,4,5], [1,0,0,0,0]);
  9. +------------------------------------------------------------------------------------------------------------------------+
  10. | array_reverse_split([1, 2, 3, 4, 5], cast(array_map((x, y) -> y, [1, 2, 3, 4, 5], [1, 0, 0, 0, 0]) as ARRAY<BOOLEAN>)) |
  11. +------------------------------------------------------------------------------------------------------------------------+
  12. | [[1], [2, 3, 4, 5]] |
  13. +------------------------------------------------------------------------------------------------------------------------+
  14. 1 row in set (0.13 sec)
  15. mysql> select array_reverse_split((x,y)->(y+1), ['a', 'b', 'c', 'd'], [-1, -1, 0, -1]);
  16. +----------------------------------------------------------------------------------------------------------------------------------------+
  17. | array_reverse_split(['a', 'b', 'c', 'd'], cast(array_map((x, y) -> (y + 1), ['a', 'b', 'c', 'd'], [-1, -1, 0, -1]) as ARRAY<BOOLEAN>)) |
  18. +----------------------------------------------------------------------------------------------------------------------------------------+
  19. | [["a", "b", "c"], ["d"]] |
  20. +----------------------------------------------------------------------------------------------------------------------------------------+
  21. 1 row in set (0.13 sec)
  22. mysql> select array_reverse_split(x->(year(x)>2013),["2020-12-12", "2013-12-12", "2015-12-12", null]);
  23. +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | array_reverse_split(['2020-12-12', '2013-12-12', '2015-12-12', NULL], array_map(x -> (year(cast(x as DATEV2)) > 2013), ['2020-12-12', '2013-12-12', '2015-12-12', NULL])) |
  25. +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | [["2020-12-12"], ["2013-12-12", "2015-12-12"], [null]] |
  27. +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. 1 row in set (0.14 sec)

keywords

ARRAY, REVERSE, SPLIT, ARRAY_REVERSE_SPLIT