Bugfix: Fix wrong function name export and function name parsing (#2786)

This commit is contained in:
Mees Delzenne 2023-10-04 14:02:20 +02:00 committed by GitHub
parent d9fa31f745
commit 8b2ae9fc99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View file

@ -84,11 +84,6 @@ pub fn ident(i: &str) -> IResult<&str, Ident> {
Ok((i, Ident::from(v)))
}
pub fn plain(i: &str) -> IResult<&str, Ident> {
let (i, v) = take_while1(val_char)(i)?;
Ok((i, Ident::from(v)))
}
pub fn multi(i: &str) -> IResult<&str, Ident> {
let (i, v) = recognize(separated_list1(tag("::"), take_while1(val_char)))(i)?;
Ok((i, Ident::from(v)))

View file

@ -71,7 +71,7 @@ impl DefineFunctionStatement {
impl fmt::Display for DefineFunctionStatement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DEFINE FUNCTION fn::{}(", self.name)?;
write!(f, "DEFINE FUNCTION fn::{}(", self.name.0)?;
for (i, (name, kind)) in self.args.iter().enumerate() {
if i > 0 {
f.write_str(", ")?;

View file

@ -48,7 +48,8 @@ impl RemoveFunctionStatement {
impl Display for RemoveFunctionStatement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "REMOVE FUNCTION fn::{}", self.name)
// Bypass ident display since we don't want backticks arround the ident.
write!(f, "REMOVE FUNCTION fn::{}", self.name.0)
}
}
@ -56,7 +57,7 @@ pub fn function(i: &str) -> IResult<&str, RemoveFunctionStatement> {
let (i, _) = tag_no_case("FUNCTION")(i)?;
let (i, _) = shouldbespace(i)?;
let (i, _) = tag("fn::")(i)?;
let (i, name) = ident::plain(i)?;
let (i, name) = ident::multi(i)?;
let (i, _) = opt(|i| {
let (i, _) = mightbespace(i)?;
let (i, _) = char('(')(i)?;
@ -71,3 +72,16 @@ pub fn function(i: &str) -> IResult<&str, RemoveFunctionStatement> {
},
))
}
#[cfg(test)]
mod test {
use super::super::remove;
#[test]
fn remove_long_function() {
let sql = "REMOVE FUNCTION fn::foo::bar::baz::bac";
let res = remove(sql);
let out = res.unwrap().1;
assert_eq!("REMOVE FUNCTION fn::foo::bar::baz::bac", format!("{}", out))
}
}