Skip to content

Commit

Permalink
dataflow-expression: Function names are case-insensitive
Browse files Browse the repository at this point in the history
SQL function names are case-insensitive, but we only accepted
all-lowercase versions of built-in functions. This commit modifies expr
lowering to compare function names case-insensitively (by calling
`to_lowercase` before matching on the name of the function).

Change-Id: Iac210a890c9702924688e3d9eeb42ad3fd374c6f
Reviewed-on: https://gerrit.readyset.name/c/readyset/+/5889
Tested-by: Buildkite CI
Reviewed-by: Dan Wilbanks <dan@readyset.io>
  • Loading branch information
glittershark committed Aug 24, 2023
1 parent 09b705e commit a0ecb99
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
40 changes: 39 additions & 1 deletion dataflow-expression/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl BuiltinFunction {
null_on_failure: true,
};

let result = match name {
let result = match name.to_lowercase().as_str() {
"convert_tz" => {
// Type is inferred from input argument
let input = next_arg()?;
Expand Down Expand Up @@ -1281,6 +1281,44 @@ pub(crate) mod tests {
);
}

#[test]
fn call_coalesce_uppercase() {
let input = AstExpr::Call(FunctionExpr::Call {
name: "COALESCE".into(),
arguments: vec![AstExpr::Column("t.x".into()), AstExpr::Literal(2.into())],
});

let result = Expr::lower(
input,
Dialect::DEFAULT_MYSQL,
resolve_columns(|c| {
if c == "t.x".into() {
Ok((0, DfType::Int))
} else {
internal!("what's this column!?")
}
}),
)
.unwrap();

assert_eq!(
result,
Expr::Call {
func: Box::new(BuiltinFunction::Coalesce(
Expr::Column {
index: 0,
ty: DfType::Int
},
vec![Expr::Literal {
val: 2.into(),
ty: DfType::BigInt
}]
)),
ty: DfType::Int
}
);
}

#[test]
fn call_concat_with_texts() {
let input = parse_expr(ParserDialect::MySQL, "concat('My', 'SQ', 'L')").unwrap();
Expand Down
11 changes: 11 additions & 0 deletions logictests/functions.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
statement ok
create table t1 (x int, y int);

statement ok
insert into t1 (x, y) values (1, null);

query II nosort
select x, COALESCE(y, 2) FROM t1;
----
1
2

0 comments on commit a0ecb99

Please sign in to comment.