ARRAY_SPLIT
array_split
array_split
description
Syntax
ARRAY<ARRAY<T>> array_split(ARRAY<T> arg, Array<Boolean> cond)
ARRAY<ARRAY<T>> array_split(lambda, ARRAY<T0> arg0...)
- pass in two
ARRAY
of equal length, the second of which is anArray<Boolean>
, and split thearg
according to the split point to the left of the position in thecond
wheretrue
is found. - Higher-order functions, passed a lambda expression and at least one
ARRAY arg0
, splitarg0
by the left-hand side of thetrue
position in theArray<Boolean>
result of the lambda expression operation.
example
mysql> select array_split([1,2,3,4,5], [1,0,1,0,0]);
+-----------------------------------------------------------------------+
| array_split([1, 2, 3, 4, 5], cast([1, 0, 1, 0, 0] as ARRAY<BOOLEAN>)) |
+-----------------------------------------------------------------------+
| [[1, 2], [3, 4, 5]] |
+-----------------------------------------------------------------------+
1 row in set (0.09 sec)
mysql> select array_split((x,y)->y, [1,2,3,4,5], [1,0,0,0,0]);
+----------------------------------------------------------------------------------------------------------------+
| array_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>)) |
+----------------------------------------------------------------------------------------------------------------+
| [[1, 2, 3, 4, 5]] |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.13 sec)
mysql> select array_split((x,y)->(y+1), ['a', 'b', 'c', 'd'], [-1, -1, 0, -1]);
+--------------------------------------------------------------------------------------------------------------------------------+
| array_split(['a', 'b', 'c', 'd'], cast(array_map((x, y) -> (y + 1), ['a', 'b', 'c', 'd'], [-1, -1, 0, -1]) as ARRAY<BOOLEAN>)) |
+--------------------------------------------------------------------------------------------------------------------------------+
| [["a", "b"], ["c", "d"]] |
+--------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.12 sec)
mysql> select array_split(x->(year(x)>2013),["2020-12-12", "2013-12-12", "2015-12-12", null]);
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| array_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])) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [["2020-12-12", "2013-12-12"], ["2015-12-12"], [null]] |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.14 sec)
keywords
ARRAY, SPLIT, ARRAY_SPLIT