aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql
diff options
context:
space:
mode:
authoravevad <avevad@yandex-team.com>2024-12-09 11:48:43 +0300
committeravevad <avevad@yandex-team.com>2024-12-09 12:07:33 +0300
commit365b065ca32ba05d72f86723169f846d0ee12189 (patch)
tree5e038eb3e468aa71927441b964e326a0cbbb2e1c /yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql
parentbc7efd59c3940f609c01a8af3ea6c6d69cbc456c (diff)
downloadydb-365b065ca32ba05d72f86723169f846d0ee12189.tar.gz
YQL-19123 More SQL features for Variant type
More SQL features for Variant type commit_hash:51c15343e2d24190ec59085888dfa3fd008cafcc
Diffstat (limited to 'yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql')
-rw-r--r--yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql30
1 files changed, 30 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql b/yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql
new file mode 100644
index 0000000000..71a09810da
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/expr/variant_struct_builtins.sql
@@ -0,0 +1,30 @@
+$vartype = Variant<num: Int32, flag: Bool, str: String>;
+$handle_num = ($x) -> { return 2 * $x; };
+$handle_flag = ($x) -> { return If($x, 200, 10); };
+$handle_str = ($x) -> { return Unwrap(CAST(LENGTH($x) AS Int32)); };
+
+$visitor = ($var) -> { return Visit($var, $handle_num AS num, $handle_flag AS flag, $handle_str AS str); };
+SELECT
+ $visitor(Variant(5, "num", $vartype)),
+ $visitor(Just(Variant(True, "flag", $vartype))),
+ $visitor(Just(Variant("somestr", "str", $vartype))),
+ $visitor(Nothing(OptionalType($vartype))),
+ $visitor(NULL)
+;
+
+$visitor_def = ($var) -> { return VisitOrDefault($var, 999, $handle_num AS num, $handle_flag AS flag); };
+SELECT
+ $visitor_def(Variant(5, "num", $vartype)),
+ $visitor_def(Just(Variant(True, "flag", $vartype))),
+ $visitor_def(Just(Variant("somestr", "str", $vartype))),
+ $visitor_def(Nothing(OptionalType($vartype))),
+ $visitor_def(NULL)
+;
+
+$vartype1 = Variant<num1: Int32, num2: Int32, num3: Int32>;
+SELECT
+ VariantItem(Variant(7, "num2", $vartype1)),
+ VariantItem(Just(Variant(5, "num1", $vartype1))),
+ VariantItem(Nothing(OptionalType($vartype1))),
+ VariantItem(NULL)
+; \ No newline at end of file