Skip to content
Snippets Groups Projects
Commit 93dc653d authored by Arseniy Volynets's avatar Arseniy Volynets :boy_tone5:
Browse files

feat: export lower/upper string functions

parent bbcb04cc
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -29,6 +29,10 @@ expression ::= ('NOT'* (
| to_char
| to_date
| trim
| substr
| lower
| upper
| '(' expression ')'
| 'NOT'? 'EXISTS' '(' dql ')'
| '(' dql ')'
| '(' expression (',' expression)* ')'
......@@ -56,6 +60,9 @@ trim ::= 'TRIM' '('
((('LEADING' | 'TRAILING' | 'BOTH')? removal_chars
| ('LEADING' | 'TRAILING' | 'BOTH')) 'FROM')? string ')'
substr ::= 'SUBSTR' '(' string ',' from (',' count)? ')'
lower ::= 'LOWER' '(' string ')'
upper ::= 'UPPER' '(' string ')'
substr ::= 'SUBSTR' '(' string ',' from (',' count)? ')'
values ::= 'VALUES'
('(' (expression(',' expression)*) ')')
(',' ('(' (expression(',' expression)*) ')'))*
......
......@@ -698,6 +698,34 @@ g.test_union_operator_works = function ()
})
end
g.test_lower_upper = function ()
local api = cluster:server("api-1").net_box
local meta = {
{name = "a", type = "string"},
{name = "b", type = "string"},
}
local r, err = api:call("sbroad.execute", { [[
select lower("COLUMN_1") as a, upper("COLUMN_1") as b from (values ('Aba'))
]] })
t.assert_equals(err, nil)
t.assert_equals(r.metadata, meta)
t.assert_equals(r.rows, {
{'aba', 'ABA'}
})
r, err = api:call("sbroad.execute", { [[
select upper(lower("COLUMN_1")) as a, lower(upper("COLUMN_1")) as b from (values ('Aba'))
]] })
t.assert_equals(err, nil)
t.assert_equals(r.metadata, meta)
t.assert_equals(r.rows, {
{'ABA', 'aba'}
})
end
g.test_like_works = function ()
local api = cluster:server("api-1").net_box
......
......@@ -80,6 +80,8 @@ pub fn get_builtin_functions() -> &'static [Function] {
Function::new_stable("to_date".into(), Type::Datetime, false),
Function::new_stable("to_char".into(), Type::String, false),
Function::new_stable("substr".into(), Type::String, true),
Function::new_stable("lower".into(), Type::String, true),
Function::new_stable("upper".into(), Type::String, true),
]
})
}
......
use crate::ir::transformation::helpers::sql_to_optimized_ir;
use pretty_assertions::assert_eq;
#[test]
fn lower_upper() {
let input = r#"select upper(lower('a' || 'B')), upper(a) from t1"#;
let plan = sql_to_optimized_ir(input, vec![]);
println!("{}", plan.as_explain().unwrap());
let expected_explain = String::from(
r#"projection (upper((lower((ROW('a'::string) || ROW('B'::string)))::string))::string -> "col_1", upper(("t1"."a"::string))::string -> "col_2")
scan "t1"
execution options:
sql_vdbe_max_steps = 45000
vtable_max_rows = 5000
"#,
);
assert_eq!(expected_explain, plan.as_explain().unwrap());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment