diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-11-20 17:37:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 17:37:57 +0000 |
commit | f76323e9b295c15751e51e3443aa47a36bee8023 (patch) | |
tree | 4113c8cad473a33e0f746966e0cf087252fa1d7a /yql/essentials/tests/sql/suites/lambda | |
parent | 753ecb8d410a4cb459c26f3a0082fb2d1724fe63 (diff) | |
parent | a7b9a6afea2a9d7a7bfac4c5eb4c1a8e60adb9e6 (diff) | |
download | ydb-f76323e9b295c15751e51e3443aa47a36bee8023.tar.gz |
Merge pull request #11788 from ydb-platform/mergelibs-241120-1113
Library import 241120-1113
Diffstat (limited to 'yql/essentials/tests/sql/suites/lambda')
19 files changed, 182 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/suites/lambda/default.cfg b/yql/essentials/tests/sql/suites/lambda/default.cfg new file mode 100644 index 0000000000..58878f8945 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/default.cfg @@ -0,0 +1 @@ +in Input input.txt diff --git a/yql/essentials/tests/sql/suites/lambda/input.txt b/yql/essentials/tests/sql/suites/lambda/input.txt new file mode 100644 index 0000000000..65949ea745 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/input.txt @@ -0,0 +1,4 @@ +{"key"="075";"subkey"="1";"value"="abc"}; +{"key"="800";"subkey"="2";"value"="ddd"}; +{"key"="020";"subkey"="3";"value"="q"}; +{"key"="150";"subkey"="4";"value"="qzz"}; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_brief.sql b/yql/essentials/tests/sql/suites/lambda/lambda_brief.sql new file mode 100644 index 0000000000..aac6edfa5b --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_brief.sql @@ -0,0 +1,3 @@ +/* postgres can not */ +/* syntax version 1 */ +select ($x, $y) -> ($x + $y)(1, 2);
\ No newline at end of file diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_duplicate_arg.sqlx b/yql/essentials/tests/sql/suites/lambda/lambda_duplicate_arg.sqlx new file mode 100644 index 0000000000..9b504d6a76 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_duplicate_arg.sqlx @@ -0,0 +1,13 @@ +/* postgres can not */ +USE plato; + +$shiftSteps=1; +$linear = ($x, $z, $x)->{ -- $x is duplicated + $v = 10 * $z + $x; + $shift = ($item) -> {return $item << $shiftSteps}; + $res = Math::Floor(Math::Pi() * $shift($v)); + return $res +}; + +--INSERT INTO Output +SELECT t.*, $linear(cast(key as uint64), cast(subkey as uint64)) FROM Input as t; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_no_aggrs.sqlx b/yql/essentials/tests/sql/suites/lambda/lambda_no_aggrs.sqlx new file mode 100644 index 0000000000..18375de71a --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_no_aggrs.sqlx @@ -0,0 +1,9 @@ +USE plato; + +$f = ()->{ + return sum(1); +}; + +SELECT + $f() +FROM Input diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_no_arg.sql b/yql/essentials/tests/sql/suites/lambda/lambda_no_arg.sql new file mode 100644 index 0000000000..e86773d9e3 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_no_arg.sql @@ -0,0 +1,10 @@ +/* postgres can not */ +$modVal = ()->{ + return 2 +}; + +$filter = ($item)->{ + return not ($item % $modVal() == 0) +}; + +SELECT ListFilter(AsList(1,2,3,4,5), $filter); diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_no_columns.sqlx b/yql/essentials/tests/sql/suites/lambda/lambda_no_columns.sqlx new file mode 100644 index 0000000000..ded3f046b8 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_no_columns.sqlx @@ -0,0 +1,9 @@ +USE plato; + +$f = ()->{ + return value; +}; + +SELECT + $f() +FROM Input diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_no_dollar_arg.sqlx b/yql/essentials/tests/sql/suites/lambda/lambda_no_dollar_arg.sqlx new file mode 100644 index 0000000000..02a5d630fb --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_no_dollar_arg.sqlx @@ -0,0 +1,13 @@ +/* postgres can not */ +USE plato; + +$shiftSteps=1; +$linear = ($x, $z)->{ + $v = 10 * $z + $x; + $shift = (item) -> {return $item << $shiftSteps}; -- must use '$' for lambda arguments, should be $item + $res = Math::Floor(Math::Pi() * $shift($v)); + return $res +}; + +--INSERT INTO Output +SELECT t.*, $linear(cast(key as uint64), cast(subkey as uint64)) FROM Input as t; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_no_dollar_assign.sqlx b/yql/essentials/tests/sql/suites/lambda/lambda_no_dollar_assign.sqlx new file mode 100644 index 0000000000..8a59426c1b --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_no_dollar_assign.sqlx @@ -0,0 +1,13 @@ +/* postgres can not */ +USE plato; + +$shiftSteps=1; +$linear = ($x, $z)->{ + $v = 10 * $z + $x; + $shift = ($item) -> {return $item << $shiftSteps}; + res = Math::Floor(Math::Pi() * $shift($v)); -- no '$' in variable, should be $res = ... + return $res +}; + +--INSERT INTO Output +SELECT t.*, $linear(cast(key as uint64), cast(subkey as uint64)) FROM Input as t; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_opt_args.sql b/yql/essentials/tests/sql/suites/lambda/lambda_opt_args.sql new file mode 100644 index 0000000000..0256eeb140 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_opt_args.sql @@ -0,0 +1,4 @@ +/* postgres can not */ +/* syntax version 1 */ +$f = ($x,$y?)->($x + ($y ?? 0)); +select $f(1), $f(2, 3); diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_simple.sql b/yql/essentials/tests/sql/suites/lambda/lambda_simple.sql new file mode 100644 index 0000000000..93f7ea3e96 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_simple.sql @@ -0,0 +1,13 @@ +/* postgres can not */ +USE plato; +PRAGMA DisableSimpleColumns; + +$shiftSteps=1; +$linear = ($x, $z)->{ + $v = 10 * $z + $x; + $shift = ($item) -> {return $item << $shiftSteps}; + return $shift($v) +}; + +--INSERT INTO Output +SELECT t.*, $linear(cast(key as uint64), cast(subkey as uint64)) FROM Input as t; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_udf.cfg b/yql/essentials/tests/sql/suites/lambda/lambda_udf.cfg new file mode 100644 index 0000000000..b0a6e1e6b6 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_udf.cfg @@ -0,0 +1,2 @@ +in Input input.txt +udf math_udf diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_udf.sql b/yql/essentials/tests/sql/suites/lambda/lambda_udf.sql new file mode 100644 index 0000000000..aff4e45606 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_udf.sql @@ -0,0 +1,16 @@ +/* postgres can not */ +/* syntax version 1 */ +USE plato; + +$shiftSteps = 1; +$linear = ($x, $z) -> { + $v = 10 * $z + $x; + $shift = ($item) -> { + return $item << $shiftSteps + }; + $res = Math::Floor(Math::Pi() * $shift($v)); + return $res +}; + +--INSERT INTO Output +SELECT t.*, $linear(cast(key as uint64), cast(subkey as uint64)) as linear FROM Input as t; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_use_labmda_as_arg.sql b/yql/essentials/tests/sql/suites/lambda/lambda_use_labmda_as_arg.sql new file mode 100644 index 0000000000..dafd67ef4f --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_use_labmda_as_arg.sql @@ -0,0 +1,14 @@ +/* postgres can not */ +USE plato; +PRAGMA DisableSimpleColumns; + +$shiftSteps=($item) -> { return Cast($item % 4 as Uint8)??0 }; + +$linear = ($x, $z, $func) -> { + $v = 10 * $z + $x; + $shift = ($item, $sk) -> {return $item << $func($sk)}; + return $shift($v, $z) +}; + +--INSERT INTO Output +SELECT t.*, $linear(cast(key as uint64), cast(subkey as uint64), $shiftSteps) FROM Input as t; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_with_tie.sql b/yql/essentials/tests/sql/suites/lambda/lambda_with_tie.sql new file mode 100644 index 0000000000..83c9aa7f46 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_with_tie.sql @@ -0,0 +1,10 @@ +/* postgres can not */ +USE plato; + +$func = ($x, $y)->{ + $y, $x = AsTuple($x, $y); + return $x || "_" || $y; +}; + +--INSERT INTO Output +SELECT $func(key, subkey) as func FROM Input; diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_with_tie_bad_count_fail.cfg b/yql/essentials/tests/sql/suites/lambda/lambda_with_tie_bad_count_fail.cfg new file mode 100644 index 0000000000..4f32e1efb8 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_with_tie_bad_count_fail.cfg @@ -0,0 +1,2 @@ +xfail +in Input input.txt diff --git a/yql/essentials/tests/sql/suites/lambda/lambda_with_tie_bad_count_fail.sql b/yql/essentials/tests/sql/suites/lambda/lambda_with_tie_bad_count_fail.sql new file mode 100644 index 0000000000..5172adb751 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/lambda_with_tie_bad_count_fail.sql @@ -0,0 +1,10 @@ +/* postgres can not */ +USE plato; + +$func = ($x, $y)->{ + $y, $x = AsTuple($x, $y, $x); + return $x || "_" || $y; +}; + +--INSERT INTO Output +SELECT $func(key, subkey) as func FROM Input; diff --git a/yql/essentials/tests/sql/suites/lambda/list_aggregate.sql b/yql/essentials/tests/sql/suites/lambda/list_aggregate.sql new file mode 100644 index 0000000000..a4c1093ae7 --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/list_aggregate.sql @@ -0,0 +1,18 @@ +/* syntax version 1 */ +$subst = ($names, $indices) -> { + RETURN ListMap( + $indices, + ($index) -> { + RETURN $names[$index]; + } + ); +}; + +$table = ( + SELECT AsList("a", "b") AS names, AsList(0, 0, 1) AS indices + UNION ALL + SELECT AsList("c", "d") AS names, AsList(0, 1, 1) AS indices +); + +SELECT AGGREGATE_LIST($subst(names, indices)) +FROM $table; diff --git a/yql/essentials/tests/sql/suites/lambda/list_aggregate_flatmap.sql b/yql/essentials/tests/sql/suites/lambda/list_aggregate_flatmap.sql new file mode 100644 index 0000000000..8d88b0b78c --- /dev/null +++ b/yql/essentials/tests/sql/suites/lambda/list_aggregate_flatmap.sql @@ -0,0 +1,18 @@ +/* syntax version 1 */ +$subst = ($names, $indices) -> { + RETURN ListFlatMap( + $indices, + ($index) -> { + RETURN $names[$index]; + } + ); +}; + +$table = ( + SELECT AsList("a", "b") AS names, AsList(0, 0, 1) AS indices + UNION ALL + SELECT AsList("c", "d") AS names, AsList(0, 1, 1) AS indices +); + +SELECT AGGREGATE_LIST($subst(names, indices)) +FROM $table; |