Skip to content

Commit 53e36fa

Browse files
committed
feat: support LIKE operator
1 parent 1145b82 commit 53e36fa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

parser/src/nullable.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ fn test_expr(column_name: &str, table_name: &str, expr: &ast::Expr) -> Option<Nu
116116
ast::Expr::InList { lhs, .. } if expr_matches_name(column_name, table_name, lhs) => {
117117
return Some(NullableResult::NotNull);
118118
}
119+
ast::Expr::Like { lhs, rhs, .. }
120+
if expr_matches_name(column_name, table_name, lhs)
121+
|| expr_matches_name(column_name, table_name, rhs) =>
122+
{
123+
return Some(NullableResult::NotNull)
124+
}
119125
// column is null
120126
ast::Expr::Binary(left, ast::Operator::Is, right)
121127
if **right == ast::Expr::Literal(ast::Literal::Null)
@@ -362,4 +368,24 @@ mod tests {
362368
Some(NullableResult::NotNull)
363369
);
364370
}
371+
372+
#[test]
373+
fn support_like_operator() {
374+
assert_eq!(
375+
is_column_nullable("id", "foo", "select * from foo f where id like ?"),
376+
Some(NullableResult::NotNull)
377+
);
378+
assert_eq!(
379+
is_column_nullable("id", "foo", "select * from foo f where id not like ?"),
380+
Some(NullableResult::NotNull)
381+
);
382+
assert_eq!(
383+
is_column_nullable("id", "foo", "select * from foo f where ? like id"),
384+
Some(NullableResult::NotNull)
385+
);
386+
assert_eq!(
387+
is_column_nullable("id", "foo", "select * from foo f where ? not like id"),
388+
Some(NullableResult::NotNull)
389+
);
390+
}
365391
}

0 commit comments

Comments
 (0)