SelectDB Cloud
SQL 手册
SQL 函数
数组函数
ARRAY_REVERSE_SPLIT

array_sortby

array_reverse_split

description

Syntax

ARRAY<ARRAY<T>> array_reverse_split(ARRAY<T> arg, Array<Boolean> cond)
ARRAY<ARRAY<T>> array_reverse_split(lambda, ARRAY<T0> arg0...)
  1. 传入两个长度相等的 ARRAY 且第二个为 Array<Boolean>,按照 cond 中为 true 的位置右侧作为分割点,分割 arg
  2. 高阶函数,传入一个 lambda 表达式和至少一个 ARRAY arg0,则按照 lambda 表达式运算得到的 Array<Boolean> 结果,其中为 true 的位置右侧作为分割点,分割 arg0

example

mysql> 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]]                                                         |
+-------------------------------------------------------------------------------+
1 row in set (0.12 sec)

mysql> 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]]                                                                                                    |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.13 sec)

mysql> 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"]]                                                                                                               |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.13 sec)

mysql> 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]]                                                                                                                    |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.14 sec)

keywords

ARRAY, REVERSE, SPLIT, ARRAY_REVERSE_SPLIT

© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标