mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
feat: support PGOverlap operator (#912)
This commit is contained in:
parent
20ac38b4da
commit
a50671d95d
4 changed files with 19 additions and 2 deletions
|
@ -95,6 +95,7 @@ pub enum BinaryOperator {
|
||||||
PGBitwiseShiftLeft,
|
PGBitwiseShiftLeft,
|
||||||
PGBitwiseShiftRight,
|
PGBitwiseShiftRight,
|
||||||
PGExp,
|
PGExp,
|
||||||
|
PGOverlap,
|
||||||
PGRegexMatch,
|
PGRegexMatch,
|
||||||
PGRegexIMatch,
|
PGRegexIMatch,
|
||||||
PGRegexNotMatch,
|
PGRegexNotMatch,
|
||||||
|
@ -135,6 +136,7 @@ impl fmt::Display for BinaryOperator {
|
||||||
BinaryOperator::PGBitwiseShiftLeft => f.write_str("<<"),
|
BinaryOperator::PGBitwiseShiftLeft => f.write_str("<<"),
|
||||||
BinaryOperator::PGBitwiseShiftRight => f.write_str(">>"),
|
BinaryOperator::PGBitwiseShiftRight => f.write_str(">>"),
|
||||||
BinaryOperator::PGExp => f.write_str("^"),
|
BinaryOperator::PGExp => f.write_str("^"),
|
||||||
|
BinaryOperator::PGOverlap => f.write_str("&&"),
|
||||||
BinaryOperator::PGRegexMatch => f.write_str("~"),
|
BinaryOperator::PGRegexMatch => f.write_str("~"),
|
||||||
BinaryOperator::PGRegexIMatch => f.write_str("~*"),
|
BinaryOperator::PGRegexIMatch => f.write_str("~*"),
|
||||||
BinaryOperator::PGRegexNotMatch => f.write_str("!~"),
|
BinaryOperator::PGRegexNotMatch => f.write_str("!~"),
|
||||||
|
|
|
@ -1662,6 +1662,9 @@ impl<'a> Parser<'a> {
|
||||||
Token::Sharp if dialect_of!(self is PostgreSqlDialect) => {
|
Token::Sharp if dialect_of!(self is PostgreSqlDialect) => {
|
||||||
Some(BinaryOperator::PGBitwiseXor)
|
Some(BinaryOperator::PGBitwiseXor)
|
||||||
}
|
}
|
||||||
|
Token::Overlap if dialect_of!(self is PostgreSqlDialect | GenericDialect) => {
|
||||||
|
Some(BinaryOperator::PGOverlap)
|
||||||
|
}
|
||||||
Token::Tilde => Some(BinaryOperator::PGRegexMatch),
|
Token::Tilde => Some(BinaryOperator::PGRegexMatch),
|
||||||
Token::TildeAsterisk => Some(BinaryOperator::PGRegexIMatch),
|
Token::TildeAsterisk => Some(BinaryOperator::PGRegexIMatch),
|
||||||
Token::ExclamationMarkTilde => Some(BinaryOperator::PGRegexNotMatch),
|
Token::ExclamationMarkTilde => Some(BinaryOperator::PGRegexNotMatch),
|
||||||
|
@ -2050,6 +2053,7 @@ impl<'a> Parser<'a> {
|
||||||
Token::LBracket
|
Token::LBracket
|
||||||
| Token::LongArrow
|
| Token::LongArrow
|
||||||
| Token::Arrow
|
| Token::Arrow
|
||||||
|
| Token::Overlap
|
||||||
| Token::HashArrow
|
| Token::HashArrow
|
||||||
| Token::HashLongArrow
|
| Token::HashLongArrow
|
||||||
| Token::AtArrow
|
| Token::AtArrow
|
||||||
|
|
|
@ -150,6 +150,8 @@ pub enum Token {
|
||||||
ShiftLeft,
|
ShiftLeft,
|
||||||
/// `>>`, a bitwise shift right operator in PostgreSQL
|
/// `>>`, a bitwise shift right operator in PostgreSQL
|
||||||
ShiftRight,
|
ShiftRight,
|
||||||
|
/// '&&', an overlap operator in PostgreSQL
|
||||||
|
Overlap,
|
||||||
/// Exclamation Mark `!` used for PostgreSQL factorial operator
|
/// Exclamation Mark `!` used for PostgreSQL factorial operator
|
||||||
ExclamationMark,
|
ExclamationMark,
|
||||||
/// Double Exclamation Mark `!!` used for PostgreSQL prefix factorial operator
|
/// Double Exclamation Mark `!!` used for PostgreSQL prefix factorial operator
|
||||||
|
@ -158,7 +160,7 @@ pub enum Token {
|
||||||
AtSign,
|
AtSign,
|
||||||
/// `|/`, a square root math operator in PostgreSQL
|
/// `|/`, a square root math operator in PostgreSQL
|
||||||
PGSquareRoot,
|
PGSquareRoot,
|
||||||
/// `||/` , a cube root math operator in PostgreSQL
|
/// `||/`, a cube root math operator in PostgreSQL
|
||||||
PGCubeRoot,
|
PGCubeRoot,
|
||||||
/// `?` or `$` , a prepared statement arg placeholder
|
/// `?` or `$` , a prepared statement arg placeholder
|
||||||
Placeholder(String),
|
Placeholder(String),
|
||||||
|
@ -245,6 +247,7 @@ impl fmt::Display for Token {
|
||||||
Token::AtSign => f.write_str("@"),
|
Token::AtSign => f.write_str("@"),
|
||||||
Token::ShiftLeft => f.write_str("<<"),
|
Token::ShiftLeft => f.write_str("<<"),
|
||||||
Token::ShiftRight => f.write_str(">>"),
|
Token::ShiftRight => f.write_str(">>"),
|
||||||
|
Token::Overlap => f.write_str("&&"),
|
||||||
Token::PGSquareRoot => f.write_str("|/"),
|
Token::PGSquareRoot => f.write_str("|/"),
|
||||||
Token::PGCubeRoot => f.write_str("||/"),
|
Token::PGCubeRoot => f.write_str("||/"),
|
||||||
Token::Placeholder(ref s) => write!(f, "{s}"),
|
Token::Placeholder(ref s) => write!(f, "{s}"),
|
||||||
|
@ -858,7 +861,14 @@ impl<'a> Tokenizer<'a> {
|
||||||
'\\' => self.consume_and_return(chars, Token::Backslash),
|
'\\' => self.consume_and_return(chars, Token::Backslash),
|
||||||
'[' => self.consume_and_return(chars, Token::LBracket),
|
'[' => self.consume_and_return(chars, Token::LBracket),
|
||||||
']' => self.consume_and_return(chars, Token::RBracket),
|
']' => self.consume_and_return(chars, Token::RBracket),
|
||||||
'&' => self.consume_and_return(chars, Token::Ampersand),
|
'&' => {
|
||||||
|
chars.next(); // consume the '&'
|
||||||
|
match chars.peek() {
|
||||||
|
Some('&') => self.consume_and_return(chars, Token::Overlap),
|
||||||
|
// Bitshift '&' operator
|
||||||
|
_ => Ok(Some(Token::Ampersand)),
|
||||||
|
}
|
||||||
|
}
|
||||||
'^' => self.consume_and_return(chars, Token::Caret),
|
'^' => self.consume_and_return(chars, Token::Caret),
|
||||||
'{' => self.consume_and_return(chars, Token::LBrace),
|
'{' => self.consume_and_return(chars, Token::LBrace),
|
||||||
'}' => self.consume_and_return(chars, Token::RBrace),
|
'}' => self.consume_and_return(chars, Token::RBrace),
|
||||||
|
|
|
@ -1613,6 +1613,7 @@ fn parse_pg_binary_ops() {
|
||||||
("^", BinaryOperator::PGExp, pg()),
|
("^", BinaryOperator::PGExp, pg()),
|
||||||
(">>", BinaryOperator::PGBitwiseShiftRight, pg_and_generic()),
|
(">>", BinaryOperator::PGBitwiseShiftRight, pg_and_generic()),
|
||||||
("<<", BinaryOperator::PGBitwiseShiftLeft, pg_and_generic()),
|
("<<", BinaryOperator::PGBitwiseShiftLeft, pg_and_generic()),
|
||||||
|
("&&", BinaryOperator::PGOverlap, pg()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (str_op, op, dialects) in binary_ops {
|
for (str_op, op, dialects) in binary_ops {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue