aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials
diff options
context:
space:
mode:
authoravevad <avevad@yandex-team.com>2024-12-11 14:21:36 +0300
committerVitaly Isaev <vitalyisaev@ydb.tech>2024-12-12 10:12:06 +0000
commit0f512bb21b67e34519e7f78de3a792091d7760e4 (patch)
tree860429f764510f9d6366de33a66ea2284f27f77b /yql/essentials
parentab4ac36b6b8137f19724a1c8954d30374d1db47d (diff)
downloadydb-0f512bb21b67e34519e7f78de3a792091d7760e4.tar.gz
YQL-19123 Move default argument in VisitOrDefault
Change order of arguments in VisitOrDefault commit_hash:60f1e45096fa62bca6c999fb14abf81754f51e1a
Diffstat (limited to 'yql/essentials')
-rw-r--r--yql/essentials/sql/v1/builtin.cpp16
-rw-r--r--yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_builtins_opt_/formatted.sql2
-rw-r--r--yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_tuple_builtins_/formatted.sql2
-rw-r--r--yql/essentials/tests/sql/suites/expr/variant_builtins_opt.sql2
-rw-r--r--yql/essentials/tests/sql/suites/expr/variant_tuple_builtins.sql2
5 files changed, 14 insertions, 10 deletions
diff --git a/yql/essentials/sql/v1/builtin.cpp b/yql/essentials/sql/v1/builtin.cpp
index a4bec63066..b7d29303cd 100644
--- a/yql/essentials/sql/v1/builtin.cpp
+++ b/yql/essentials/sql/v1/builtin.cpp
@@ -3731,16 +3731,20 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
dflt = positional.GetTupleElement(positional.GetTupleSize() - 1);
}
} else {
+ size_t minArgs = withDefault ? 2 : 1;
+ if (args.size() < minArgs) {
+ return new TInvalidBuiltin(pos, TStringBuilder() << name
+ << " requires at least " << minArgs << " positional arguments");
+ }
variant = args[0];
- size_t defaultSuffix = withDefault ? 1 : 0;
- labels.reserve(args.size() - 1 - defaultSuffix);
- handlers.reserve(args.size() - 1 - defaultSuffix);
- for (size_t idx = 0; idx + 1 < args.size() - defaultSuffix; idx++) {
+ labels.reserve(args.size() - minArgs);
+ handlers.reserve(args.size() - minArgs);
+ for (size_t idx = 0; idx < args.size() - minArgs; idx++) {
labels.push_back(BuildQuotedAtom(pos, ToString(idx)));
- handlers.push_back(args[idx + 1]);
+ handlers.push_back(args[minArgs + idx]);
}
if (withDefault) {
- dflt = args.back();
+ dflt = args[1];
}
}
TVector<TNodePtr> resultArgs;
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_builtins_opt_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_builtins_opt_/formatted.sql
index 3023dcf5c2..e4aa4de0a1 100644
--- a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_builtins_opt_/formatted.sql
+++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_builtins_opt_/formatted.sql
@@ -25,6 +25,6 @@ $var_2 = VARIANT ("8", "1", $vartype_t);
SELECT
Visit(Just($var_1), $handle_a, $handle_b),
Visit(Just($var_2), $handle_a, $handle_b),
- VisitOrDefault(Just($var_2), $handle_a, Just(777u)),
+ VisitOrDefault(Just($var_2), Just(777u), $handle_a),
VariantItem(Just($var_b))
;
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_tuple_builtins_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_tuple_builtins_/formatted.sql
index b1e21cda10..bdca3d25be 100644
--- a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_tuple_builtins_/formatted.sql
+++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_expr-variant_tuple_builtins_/formatted.sql
@@ -25,7 +25,7 @@ SELECT
;
$visitor_def = ($var) -> {
- RETURN VisitOrDefault($var, $handle_num, $handle_flag, 999);
+ RETURN VisitOrDefault($var, 999, $handle_num, $handle_flag);
};
SELECT
diff --git a/yql/essentials/tests/sql/suites/expr/variant_builtins_opt.sql b/yql/essentials/tests/sql/suites/expr/variant_builtins_opt.sql
index 443802fe56..3d28d3f09a 100644
--- a/yql/essentials/tests/sql/suites/expr/variant_builtins_opt.sql
+++ b/yql/essentials/tests/sql/suites/expr/variant_builtins_opt.sql
@@ -21,6 +21,6 @@ $var_2 = Variant("8", "1", $vartype_t);
SELECT
Visit(Just($var_1), $handle_a, $handle_b),
Visit(Just($var_2), $handle_a, $handle_b),
- VisitOrDefault(Just($var_2), $handle_a, Just(777u)),
+ VisitOrDefault(Just($var_2), Just(777u), $handle_a),
VariantItem(Just($var_b))
;
diff --git a/yql/essentials/tests/sql/suites/expr/variant_tuple_builtins.sql b/yql/essentials/tests/sql/suites/expr/variant_tuple_builtins.sql
index 35d1775708..075f061974 100644
--- a/yql/essentials/tests/sql/suites/expr/variant_tuple_builtins.sql
+++ b/yql/essentials/tests/sql/suites/expr/variant_tuple_builtins.sql
@@ -12,7 +12,7 @@ SELECT
$visitor(NULL)
;
-$visitor_def = ($var) -> { return VisitOrDefault($var, $handle_num, $handle_flag, 999); };
+$visitor_def = ($var) -> { return VisitOrDefault($var, 999, $handle_num, $handle_flag); };
SELECT
$visitor_def(Variant(5, "0", $vartype)),
$visitor_def(Just(Variant(True, "1", $vartype))),