mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-29 14:27:36 +00:00
Fix parsing of equality binop in function argument (#1182)
This commit is contained in:
parent
e976a2ee43
commit
3bf40485c5
5 changed files with 64 additions and 18 deletions
|
|
@ -33,4 +33,8 @@ impl Dialect for DuckDbDialect {
|
|||
fn supports_group_by_expr(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn supports_named_fn_args_with_eq_operator(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,6 +143,10 @@ pub trait Dialect: Debug + Any {
|
|||
fn supports_start_transaction_modifier(&self) -> bool {
|
||||
false
|
||||
}
|
||||
/// Returns true if the dialect supports named arguments of the form FUN(a = '1', b = '2').
|
||||
fn supports_named_fn_args_with_eq_operator(&self) -> bool {
|
||||
false
|
||||
}
|
||||
/// Returns true if the dialect has a CONVERT function which accepts a type first
|
||||
/// and an expression second, e.g. `CONVERT(varchar, 1)`
|
||||
fn convert_type_before_value(&self) -> bool {
|
||||
|
|
|
|||
|
|
@ -8631,7 +8631,9 @@ impl<'a> Parser<'a> {
|
|||
arg,
|
||||
operator: FunctionArgOperator::RightArrow,
|
||||
})
|
||||
} else if self.peek_nth_token(1) == Token::Eq {
|
||||
} else if self.dialect.supports_named_fn_args_with_eq_operator()
|
||||
&& self.peek_nth_token(1) == Token::Eq
|
||||
{
|
||||
let name = self.parse_identifier(false)?;
|
||||
|
||||
self.expect_token(&Token::Eq)?;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl TestedDialects {
|
|||
}
|
||||
Some((dialect, parsed))
|
||||
})
|
||||
.unwrap()
|
||||
.expect("tested dialects cannot be empty")
|
||||
.1
|
||||
}
|
||||
|
||||
|
|
@ -195,15 +195,6 @@ impl TestedDialects {
|
|||
|
||||
/// Returns all available dialects.
|
||||
pub fn all_dialects() -> TestedDialects {
|
||||
all_dialects_except(|_| false)
|
||||
}
|
||||
|
||||
/// Returns available dialects. The `except` predicate is used
|
||||
/// to filter out specific dialects.
|
||||
pub fn all_dialects_except<F>(except: F) -> TestedDialects
|
||||
where
|
||||
F: Fn(&dyn Dialect) -> bool,
|
||||
{
|
||||
let all_dialects = vec![
|
||||
Box::new(GenericDialect {}) as Box<dyn Dialect>,
|
||||
Box::new(PostgreSqlDialect {}) as Box<dyn Dialect>,
|
||||
|
|
@ -218,14 +209,30 @@ where
|
|||
Box::new(DuckDbDialect {}) as Box<dyn Dialect>,
|
||||
];
|
||||
TestedDialects {
|
||||
dialects: all_dialects
|
||||
.into_iter()
|
||||
.filter(|d| !except(d.as_ref()))
|
||||
.collect(),
|
||||
dialects: all_dialects,
|
||||
options: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns all dialects matching the given predicate.
|
||||
pub fn all_dialects_where<F>(predicate: F) -> TestedDialects
|
||||
where
|
||||
F: Fn(&dyn Dialect) -> bool,
|
||||
{
|
||||
let mut dialects = all_dialects();
|
||||
dialects.dialects.retain(|d| predicate(&**d));
|
||||
dialects
|
||||
}
|
||||
|
||||
/// Returns available dialects. The `except` predicate is used
|
||||
/// to filter out specific dialects.
|
||||
pub fn all_dialects_except<F>(except: F) -> TestedDialects
|
||||
where
|
||||
F: Fn(&dyn Dialect) -> bool,
|
||||
{
|
||||
all_dialects_where(|d| !except(d))
|
||||
}
|
||||
|
||||
pub fn assert_eq_vec<T: ToString>(expected: &[&str], actual: &[T]) {
|
||||
assert_eq!(
|
||||
expected,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue