ARRAY_REVERSE_SPLIT
Descriptionβ
- pass in two
ARRAY
of equal length, the second of which is anArray<Boolean>
, and split thearg
according to the split point to the right of the position in thecond
that istrue
. - Higher-order functions, passed a lambda expression and at least one
ARRAY arg0
, splitarg0
by the right-hand side of thetrue
position in thecond
of theArray<Boolean>
result of the operation on the lambda expression.
Syntaxβ
ARRAY_REVERSE_SPLIT(<arr>, <cond>)
ARRAY_REVERSE_SPLIT(<lambda>, <arr> [, ...])
Parametersβ
Parameter | Description |
---|---|
<lambda> | A lambda expression where the input parameters must match the number of columns in the given array. The expression can execute valid scalar functions but does not support aggregate functions. |
<arr> | ARRAY array |
Return Valueβ
Returns an ARRAY type result, where the array is split according to the specified condition.
Exampleβ
select array_reverse_split([1,2,3,4,5], [1,0,1,0,0]);
+-------------------------------------------------------------------------------+
| array_reverse_split([1, 2, 3, 4, 5], cast([1, 0, 1, 0, 0] as ARRAY<BOOLEAN>)) |
+-------------------------------------------------------------------------------+
| [[1], [2, 3], [4, 5]] |
+-------------------------------------------------------------------------------+
select array_reverse_split((x,y)->y, [1,2,3,4,5], [1,0,0,0,0]);
+------------------------------------------------------------------------------------------------------------------------+
| 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>)) |
+------------------------------------------------------------------------------------------------------------------------+
| [[1], [2, 3, 4, 5]] |
+------------------------------------------------------------------------------------------------------------------------+
select array_reverse_split((x,y)->(y+1), ['a', 'b', 'c', 'd'], [-1, -1, 0, -1]);
+----------------------------------------------------------------------------------------------------------------------------------------+
| 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>)) |
+----------------------------------------------------------------------------------------------------------------------------------------+
| [["a", "b", "c"], ["d"]] |
+----------------------------------------------------------------------------------------------------------------------------------------+
select array_reverse_split(x->(year(x)>2013),["2020-12-12", "2013-12-12", "2015-12-12", null]);
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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])) |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [["2020-12-12"], ["2013-12-12", "2015-12-12"], [null]] |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+