diff options
author | udovichenko-r <udovichenko-r@yandex-team.com> | 2024-11-19 14:58:38 +0300 |
---|---|---|
committer | udovichenko-r <udovichenko-r@yandex-team.com> | 2024-11-19 15:16:27 +0300 |
commit | 24521403b1c44303e043ba540c09b1fe991c7474 (patch) | |
tree | 341d1e7206bc7c143d04d2d96f05b6dc0655606d /yql/essentials/tests/sql/suites/expr/list_builtins.sql | |
parent | 72b3cd51dc3fb9d16975d353ea82fd85701393cc (diff) | |
download | ydb-24521403b1c44303e043ba540c09b1fe991c7474.tar.gz |
YQL-19206 Move contrib/ydb/library/yql/tests/sql/suites -> yql/essentials/tests/sql/suites
commit_hash:d0ef1f92b09c94db7c2408f946d2a4c62b603f00
Diffstat (limited to 'yql/essentials/tests/sql/suites/expr/list_builtins.sql')
-rw-r--r-- | yql/essentials/tests/sql/suites/expr/list_builtins.sql | 70 |
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); |