mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-21 14:40:18 +00:00
feat: Allow to use >> and << binary operators in Generic dialect (#553)
This commit is contained in:
parent
076b587bb2
commit
6c98228e71
3 changed files with 11 additions and 10 deletions
|
@ -1145,10 +1145,10 @@ impl<'a> Parser<'a> {
|
||||||
Token::Caret => Some(BinaryOperator::BitwiseXor),
|
Token::Caret => Some(BinaryOperator::BitwiseXor),
|
||||||
Token::Ampersand => Some(BinaryOperator::BitwiseAnd),
|
Token::Ampersand => Some(BinaryOperator::BitwiseAnd),
|
||||||
Token::Div => Some(BinaryOperator::Divide),
|
Token::Div => Some(BinaryOperator::Divide),
|
||||||
Token::ShiftLeft if dialect_of!(self is PostgreSqlDialect) => {
|
Token::ShiftLeft if dialect_of!(self is PostgreSqlDialect | GenericDialect) => {
|
||||||
Some(BinaryOperator::PGBitwiseShiftLeft)
|
Some(BinaryOperator::PGBitwiseShiftLeft)
|
||||||
}
|
}
|
||||||
Token::ShiftRight if dialect_of!(self is PostgreSqlDialect) => {
|
Token::ShiftRight if dialect_of!(self is PostgreSqlDialect | GenericDialect) => {
|
||||||
Some(BinaryOperator::PGBitwiseShiftRight)
|
Some(BinaryOperator::PGBitwiseShiftRight)
|
||||||
}
|
}
|
||||||
Token::Sharp if dialect_of!(self is PostgreSqlDialect) => {
|
Token::Sharp if dialect_of!(self is PostgreSqlDialect) => {
|
||||||
|
|
|
@ -24,8 +24,8 @@ mod test_utils;
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use sqlparser::ast::*;
|
use sqlparser::ast::*;
|
||||||
use sqlparser::dialect::{
|
use sqlparser::dialect::{
|
||||||
AnsiDialect, BigQueryDialect, GenericDialect, HiveDialect, MsSqlDialect, PostgreSqlDialect,
|
AnsiDialect, BigQueryDialect, ClickHouseDialect, GenericDialect, HiveDialect, MsSqlDialect,
|
||||||
SQLiteDialect, SnowflakeDialect,
|
PostgreSqlDialect, SQLiteDialect, SnowflakeDialect,
|
||||||
};
|
};
|
||||||
use sqlparser::keywords::ALL_KEYWORDS;
|
use sqlparser::keywords::ALL_KEYWORDS;
|
||||||
use sqlparser::parser::{Parser, ParserError};
|
use sqlparser::parser::{Parser, ParserError};
|
||||||
|
@ -555,7 +555,7 @@ fn test_eof_after_as() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_infix_error() {
|
fn test_no_infix_error() {
|
||||||
let res = Parser::parse_sql(&GenericDialect {}, "ASSERT-URA<<");
|
let res = Parser::parse_sql(&ClickHouseDialect {}, "ASSERT-URA<<");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ParserError::ParserError("No infix parser for token ShiftLeft".to_string()),
|
ParserError::ParserError("No infix parser for token ShiftLeft".to_string()),
|
||||||
res.unwrap_err()
|
res.unwrap_err()
|
||||||
|
|
|
@ -1077,13 +1077,14 @@ fn parse_prepare() {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_pg_bitwise_binary_ops() {
|
fn parse_pg_bitwise_binary_ops() {
|
||||||
let bitwise_ops = &[
|
let bitwise_ops = &[
|
||||||
("#", BinaryOperator::PGBitwiseXor),
|
// Sharp char cannot be used with Generic Dialect, it conflicts with identifiers
|
||||||
(">>", BinaryOperator::PGBitwiseShiftRight),
|
("#", BinaryOperator::PGBitwiseXor, pg()),
|
||||||
("<<", BinaryOperator::PGBitwiseShiftLeft),
|
(">>", BinaryOperator::PGBitwiseShiftRight, pg_and_generic()),
|
||||||
|
("<<", BinaryOperator::PGBitwiseShiftLeft, pg_and_generic()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (str_op, op) in bitwise_ops {
|
for (str_op, op, dialects) in bitwise_ops {
|
||||||
let select = pg().verified_only_select(&format!("SELECT a {} b", &str_op));
|
let select = dialects.verified_only_select(&format!("SELECT a {} b", &str_op));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
SelectItem::UnnamedExpr(Expr::BinaryOp {
|
SelectItem::UnnamedExpr(Expr::BinaryOp {
|
||||||
left: Box::new(Expr::Identifier(Ident::new("a"))),
|
left: Box::new(Expr::Identifier(Ident::new("a"))),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue