aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Neporada <aneporada@ydb.tech>2024-01-10 20:02:37 +0300
committerGitHub <noreply@github.com>2024-01-10 20:02:37 +0300
commite75b8c5550c5f46beebf9ddc68b9b043f48b9c28 (patch)
treefe1412d8f7ae3d44ad999fe1ff00ea1b7e5f81a0
parent4944f90a4afb6439b879c12e5962f65bb1664e36 (diff)
downloadydb-e75b8c5550c5f46beebf9ddc68b9b043f48b9c28.tar.gz
support optional list in ListIndexOf (#902)
-rw-r--r--ydb/library/yql/mount/lib/yql/core.yql2
-rw-r--r--ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json22
-rw-r--r--ydb/library/yql/tests/sql/sql2yql/canondata/result.json14
-rw-r--r--ydb/library/yql/tests/sql/suites/expr/list_indexof.sql13
-rw-r--r--ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json21
5 files changed, 71 insertions, 1 deletions
diff --git a/ydb/library/yql/mount/lib/yql/core.yql b/ydb/library/yql/mount/lib/yql/core.yql
index ea51d9b5fc..9fd5be23fa 100644
--- a/ydb/library/yql/mount/lib/yql/core.yql
+++ b/ydb/library/yql/mount/lib/yql/core.yql
@@ -3,7 +3,7 @@
(let Unequals (lambda '(value) (lambda '(x) (!= x value))))
(let FindIndex (lambda '(list predicate) (block '(
- (let enumerated (Enumerate list))
+ (let enumerated (Enumerate (Coalesce list (EmptyList))))
(let filtered (Filter enumerated (lambda '(x) (Coalesce (Apply predicate (Nth x '1)) (Bool '0)))))
(return (Nth (ToOptional filtered) '0))
))))
diff --git a/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json b/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json
index 2a95c6e15e..fb6fe2f901 100644
--- a/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json
+++ b/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json
@@ -671,6 +671,28 @@
}
],
"test.test[expr-int_literals_negative_typed-default.txt-Results]": [],
+ "test.test[expr-list_indexof-default.txt-Analyze]": [
+ {
+ "checksum": "b4dd508a329723c74293d80f0278c705",
+ "size": 505,
+ "uri": "https://{canondata_backend}/995452/b1f2dabe2f59f069a24ebbb0bcf5d5b69f26631e/resource.tar.gz#test.test_expr-list_indexof-default.txt-Analyze_/plan.txt"
+ }
+ ],
+ "test.test[expr-list_indexof-default.txt-Debug]": [
+ {
+ "checksum": "9968f0a681b374cf69e8272c94c136ad",
+ "size": 1178,
+ "uri": "https://{canondata_backend}/995452/b1f2dabe2f59f069a24ebbb0bcf5d5b69f26631e/resource.tar.gz#test.test_expr-list_indexof-default.txt-Debug_/opt.yql_patched"
+ }
+ ],
+ "test.test[expr-list_indexof-default.txt-Plan]": [
+ {
+ "checksum": "b4dd508a329723c74293d80f0278c705",
+ "size": 505,
+ "uri": "https://{canondata_backend}/995452/b1f2dabe2f59f069a24ebbb0bcf5d5b69f26631e/resource.tar.gz#test.test_expr-list_indexof-default.txt-Plan_/plan.txt"
+ }
+ ],
+ "test.test[expr-list_indexof-default.txt-Results]": [],
"test.test[expr-list_to_from_tuple-default.txt-Analyze]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
diff --git a/ydb/library/yql/tests/sql/sql2yql/canondata/result.json b/ydb/library/yql/tests/sql/sql2yql/canondata/result.json
index 4dac634501..409d77064d 100644
--- a/ydb/library/yql/tests/sql/sql2yql/canondata/result.json
+++ b/ydb/library/yql/tests/sql/sql2yql/canondata/result.json
@@ -5368,6 +5368,13 @@
"uri": "https://{canondata_backend}/1936997/00f46808be87e2ae2d4ac3ac45675b659c5ace45/resource.tar.gz#test_sql2yql.test_expr-list_from_range_overflow_/sql.yql"
}
],
+ "test_sql2yql.test[expr-list_indexof]": [
+ {
+ "checksum": "144ab782fb52c5d69f1520151a052067",
+ "size": 2475,
+ "uri": "https://{canondata_backend}/995452/d567f0e593fff30f6415ec4b4d2488a3e4c452ab/resource.tar.gz#test_sql2yql.test_expr-list_indexof_/sql.yql"
+ }
+ ],
"test_sql2yql.test[expr-list_not_null]": [
{
"checksum": "cfeb0d35501073250e10cfbc3eec4629",
@@ -22686,6 +22693,13 @@
"uri": "https://{canondata_backend}/1880306/64654158d6bfb1289c66c626a8162239289559d0/resource.tar.gz#test_sql_format.test_expr-list_from_range_overflow_/formatted.sql"
}
],
+ "test_sql_format.test[expr-list_indexof]": [
+ {
+ "checksum": "a57adb914ca0edb11239bfd6bb2abd5f",
+ "size": 288,
+ "uri": "https://{canondata_backend}/995452/d567f0e593fff30f6415ec4b4d2488a3e4c452ab/resource.tar.gz#test_sql_format.test_expr-list_indexof_/formatted.sql"
+ }
+ ],
"test_sql_format.test[expr-list_not_null]": [
{
"checksum": "93d47a5831fee1d864931d381a395bf2",
diff --git a/ydb/library/yql/tests/sql/suites/expr/list_indexof.sql b/ydb/library/yql/tests/sql/suites/expr/list_indexof.sql
new file mode 100644
index 0000000000..47be99e547
--- /dev/null
+++ b/ydb/library/yql/tests/sql/suites/expr/list_indexof.sql
@@ -0,0 +1,13 @@
+$list = [1, 2, 3];
+
+$opt_list = [1, null, 2, 3];
+
+select
+ ListIndexOf($list, 2),
+ ListIndexOf($list, 100),
+ ListIndexOf(Just($opt_list), 2),
+ ListIndexOf(Just($opt_list), 200),
+ ListIndexOf(Nothing(List<Int32>?), 2),
+ ListIndexOf([], 'foo'),
+ ListIndexOf(null, 1.0),
+;
diff --git a/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json b/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json
index 6aea590697..005d1dc4ee 100644
--- a/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json
+++ b/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json
@@ -612,6 +612,27 @@
"uri": "https://{canondata_backend}/1871002/6806fa776e6f886570695001139706dd4c62370f/resource.tar.gz#test.test_expr-int_literals_negative_typed-default.txt-Results_/results.txt"
}
],
+ "test.test[expr-list_indexof-default.txt-Debug]": [
+ {
+ "checksum": "4046f783e3f0508a111f95094d4837ae",
+ "size": 1107,
+ "uri": "https://{canondata_backend}/1597364/7296385ae1f5dffe737a1cf8ab2f30e3d3465147/resource.tar.gz#test.test_expr-list_indexof-default.txt-Debug_/opt.yql"
+ }
+ ],
+ "test.test[expr-list_indexof-default.txt-Plan]": [
+ {
+ "checksum": "b4dd508a329723c74293d80f0278c705",
+ "size": 505,
+ "uri": "https://{canondata_backend}/1597364/7296385ae1f5dffe737a1cf8ab2f30e3d3465147/resource.tar.gz#test.test_expr-list_indexof-default.txt-Plan_/plan.txt"
+ }
+ ],
+ "test.test[expr-list_indexof-default.txt-Results]": [
+ {
+ "checksum": "66c769d2bfe8215e35f4d5065c8b0f3d",
+ "size": 3120,
+ "uri": "https://{canondata_backend}/1597364/7296385ae1f5dffe737a1cf8ab2f30e3d3465147/resource.tar.gz#test.test_expr-list_indexof-default.txt-Results_/results.txt"
+ }
+ ],
"test.test[expr-list_to_from_tuple-default.txt-Debug]": [
{
"checksum": "6d90d912c1af13e53aec4013f17cc329",