aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/expr/list_builtins.sql
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
commit31773f157bf8164364649b5f470f52dece0a4317 (patch)
tree33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /yql/essentials/tests/sql/suites/expr/list_builtins.sql
parent2c7938962d8689e175574fc1e817c05049f27905 (diff)
parenteff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff)
downloadydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz
Merge branch 'rightlib' into mergelibs-241120-1113
Diffstat (limited to 'yql/essentials/tests/sql/suites/expr/list_builtins.sql')
-rw-r--r--yql/essentials/tests/sql/suites/expr/list_builtins.sql70
1 files changed, 70 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/suites/expr/list_builtins.sql b/yql/essentials/tests/sql/suites/expr/list_builtins.sql
new file mode 100644
index 0000000000..66dd5a0fcf
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/expr/list_builtins.sql
@@ -0,0 +1,70 @@
+/* postgres can not */
+/* syntax version 1 */
+$list = AsList(3, 1, 2, 3);
+$other_list = AsList(4);
+$bool_list = AsList(true, false, true);
+$struct_list = AsList(
+ AsStruct(1 AS one, 2 AS two),
+ AsStruct(-1 AS one, -2 AS two)
+);
+
+$script = @@
+def formula(a, b, c, d):
+ return a * b + c // d
+@@;
+$udf = Python3::formula(
+ Callable<(Int64, Int64, Int64, Int64)->Int64>,
+ $script
+);
+
+$lambdaSum = ($x, $y) -> { RETURN $x + $y; };
+$lambdaMult = ($x) -> { RETURN 4 * $x; };
+$lambdaTuple = ($i, $s) -> { RETURN ($i * $s, $i + $s); };
+$lambdaInc = ($i) -> { RETURN ($i + 1, $i + 2); };
+
+SELECT
+ ListLength($list) AS length,
+ ListExtend($list, $other_list) AS extend,
+ ListZip($list, $other_list) AS zip,
+ ListZipAll($list, $other_list) AS zipall,
+ ListEnumerate($list) AS enumerate,
+ ListReverse($list) AS reverse,
+ ListSkip($list, 2) AS skip,
+ ListTake($list, 2) AS take,
+ ListSort($list) AS sort,
+ ListSort($struct_list, ($x) -> { return $x.two; }) AS sort_structs,
+ ListMap($list, ($item) -> { return $udf($item, 6, 4, 2); }) AS map,
+ ListFlatMap($list, ($item) -> { return $item / 0; }) AS flatmap,
+ ListFilter($list, ($item) -> { return $item < 3; }) AS filter,
+ ListAny($bool_list) AS any,
+ ListAll($bool_list) AS all,
+ ListMax($list) AS max,
+ ListMin($list) AS min,
+ ListSum($list) AS sum,
+ ListAvg($list) AS avg,
+ ListUniq($list) AS uniq,
+ ListConcat(ListMap($list, ($item) -> { return CAST($item AS String); })) AS concat,
+ ListExtract($struct_list, "two") AS extract,
+ ListMap($list, ($item) -> { return CAST($item AS Double);}),
+ ListCreate(Tuple<Int64,Double>),
+ ListCreate(TypeOf("foo")),
+ ListFold($list, 6, $lambdaSum),
+ ListFold([], 3, $lambdaSum),
+ ListFold(Just($list), 6, $lambdaSum),
+ ListFold(Just([]), 3, $lambdaSum),
+ ListFold(Null, 3, $lambdaSum),
+ ListFold1($list, $lambdaMult, $lambdaSum),
+ ListFold1([], $lambdaMult, $lambdaSum),
+ ListFold1(Just($list), $lambdaMult, $lambdaSum),
+ ListFold1(Just([]), $lambdaMult, $lambdaSum),
+ ListFold1(Null, $lambdaMult, $lambdaSum),
+ ListFoldMap($list, 1, $lambdaTuple),
+ ListFoldMap([], 1, $lambdaTuple),
+ ListFoldMap(Just($list), 1, $lambdaTuple),
+ ListFoldMap(Just([]), 1, $lambdaTuple),
+ ListFoldMap(Null, 1, $lambdaTuple),
+ ListFold1Map($list, $lambdaInc, $lambdaTuple),
+ ListFold1Map([], $lambdaInc, $lambdaTuple),
+ ListFold1Map(Just($list), $lambdaInc, $lambdaTuple),
+ ListFold1Map(Just([]), $lambdaInc, $lambdaTuple),
+ ListFold1Map(Null, $lambdaInc, $lambdaTuple);