Skip to content

Commit 90bbbcf

Browse files
yuval-illumexovr
authored andcommitted
Add support in IS boolean filter (apache#474)
* Add support in IS TRUE IS FALSE * Fix lint * Add test for is false
1 parent 804047c commit 90bbbcf

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/parser.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,21 @@ impl<'a> Parser<'a> {
11421142
{
11431143
let expr2 = self.parse_expr()?;
11441144
Ok(Expr::IsNotDistinctFrom(Box::new(expr), Box::new(expr2)))
1145+
} else if let Some(right) =
1146+
self.parse_one_of_keywords(&[Keyword::TRUE, Keyword::FALSE])
1147+
{
1148+
let mut val = Value::Boolean(true);
1149+
if right == Keyword::FALSE {
1150+
val = Value::Boolean(false);
1151+
}
1152+
Ok(Expr::BinaryOp {
1153+
left: Box::new(expr),
1154+
op: BinaryOperator::Eq,
1155+
right: Box::new(Expr::Value(val)),
1156+
})
11451157
} else {
11461158
self.expected(
1147-
"[NOT] NULL or [NOT] DISTINCT FROM after IS",
1159+
"[NOT] NULL or [NOT] DISTINCT FROM TRUE FALSE after IS",
11481160
self.peek_token(),
11491161
)
11501162
}

tests/sqlparser_common.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,3 +4717,25 @@ fn parse_time_functions() {
47174717
// Validating Parenthesis
47184718
one_statement_parses_to("SELECT CURRENT_DATE", sql);
47194719
}
4720+
4721+
#[test]
4722+
fn parse_is_boolean() {
4723+
one_statement_parses_to(
4724+
"SELECT f from foo where field is true",
4725+
"SELECT f FROM foo WHERE field = true",
4726+
);
4727+
4728+
one_statement_parses_to(
4729+
"SELECT f from foo where field is false",
4730+
"SELECT f FROM foo WHERE field = false",
4731+
);
4732+
4733+
let sql = "SELECT f from foo where field is 0";
4734+
let res = parse_sql_statements(sql);
4735+
assert_eq!(
4736+
ParserError::ParserError(
4737+
"Expected [NOT] NULL or [NOT] DISTINCT FROM TRUE FALSE after IS, found: 0".to_string()
4738+
),
4739+
res.unwrap_err()
4740+
);
4741+
}

0 commit comments

Comments
 (0)