mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-29 10:24:06 +00:00
Support unary + / -
This commit is contained in:
parent
786b1cf18a
commit
54c9ca8619
2 changed files with 30 additions and 1 deletions
|
@ -174,6 +174,7 @@ impl Parser {
|
||||||
expr: Box::new(self.parse_subexpr(p)?),
|
expr: Box::new(self.parse_subexpr(p)?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// another SQLWord:
|
||||||
_ => match self.peek_token() {
|
_ => match self.peek_token() {
|
||||||
Some(Token::LParen) => self.parse_function(w.as_sql_ident()),
|
Some(Token::LParen) => self.parse_function(w.as_sql_ident()),
|
||||||
Some(Token::Period) => {
|
Some(Token::Period) => {
|
||||||
|
@ -201,8 +202,15 @@ impl Parser {
|
||||||
}
|
}
|
||||||
_ => Ok(ASTNode::SQLIdentifier(w.as_sql_ident())),
|
_ => Ok(ASTNode::SQLIdentifier(w.as_sql_ident())),
|
||||||
},
|
},
|
||||||
},
|
}, // End of Token::SQLWord
|
||||||
Token::Mult => Ok(ASTNode::SQLWildcard),
|
Token::Mult => Ok(ASTNode::SQLWildcard),
|
||||||
|
tok @ Token::Minus | tok @ Token::Plus => {
|
||||||
|
let p = self.get_precedence(&tok)?;
|
||||||
|
Ok(ASTNode::SQLUnary {
|
||||||
|
operator: self.to_sql_operator(&tok)?,
|
||||||
|
expr: Box::new(self.parse_subexpr(p)?),
|
||||||
|
})
|
||||||
|
}
|
||||||
Token::Number(_)
|
Token::Number(_)
|
||||||
| Token::SingleQuotedString(_)
|
| Token::SingleQuotedString(_)
|
||||||
| Token::NationalStringLiteral(_) => {
|
| Token::NationalStringLiteral(_) => {
|
||||||
|
|
|
@ -174,6 +174,27 @@ fn parse_compound_expr_2() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_unary_math() {
|
||||||
|
use self::ASTNode::*;
|
||||||
|
use self::SQLOperator::*;
|
||||||
|
let sql = "- a + - b";
|
||||||
|
assert_eq!(
|
||||||
|
SQLBinaryExpr {
|
||||||
|
left: Box::new(SQLUnary {
|
||||||
|
operator: Minus,
|
||||||
|
expr: Box::new(SQLIdentifier("a".to_string())),
|
||||||
|
}),
|
||||||
|
op: Plus,
|
||||||
|
right: Box::new(SQLUnary {
|
||||||
|
operator: Minus,
|
||||||
|
expr: Box::new(SQLIdentifier("b".to_string())),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
verified_expr(sql)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_is_null() {
|
fn parse_is_null() {
|
||||||
use self::ASTNode::*;
|
use self::ASTNode::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue