mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Adds support for mysql's drop index (#1864)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
a8bde39efb
commit
80d47eee84
3 changed files with 58 additions and 11 deletions
|
@ -3405,6 +3405,9 @@ pub enum Statement {
|
||||||
purge: bool,
|
purge: bool,
|
||||||
/// MySQL-specific "TEMPORARY" keyword
|
/// MySQL-specific "TEMPORARY" keyword
|
||||||
temporary: bool,
|
temporary: bool,
|
||||||
|
/// MySQL-specific drop index syntax, which requires table specification
|
||||||
|
/// See <https://dev.mysql.com/doc/refman/8.4/en/drop-index.html>
|
||||||
|
table: Option<ObjectName>,
|
||||||
},
|
},
|
||||||
/// ```sql
|
/// ```sql
|
||||||
/// DROP FUNCTION
|
/// DROP FUNCTION
|
||||||
|
@ -5242,17 +5245,24 @@ impl fmt::Display for Statement {
|
||||||
restrict,
|
restrict,
|
||||||
purge,
|
purge,
|
||||||
temporary,
|
temporary,
|
||||||
} => write!(
|
table,
|
||||||
f,
|
} => {
|
||||||
"DROP {}{}{} {}{}{}{}",
|
write!(
|
||||||
if *temporary { "TEMPORARY " } else { "" },
|
f,
|
||||||
object_type,
|
"DROP {}{}{} {}{}{}{}",
|
||||||
if *if_exists { " IF EXISTS" } else { "" },
|
if *temporary { "TEMPORARY " } else { "" },
|
||||||
display_comma_separated(names),
|
object_type,
|
||||||
if *cascade { " CASCADE" } else { "" },
|
if *if_exists { " IF EXISTS" } else { "" },
|
||||||
if *restrict { " RESTRICT" } else { "" },
|
display_comma_separated(names),
|
||||||
if *purge { " PURGE" } else { "" }
|
if *cascade { " CASCADE" } else { "" },
|
||||||
),
|
if *restrict { " RESTRICT" } else { "" },
|
||||||
|
if *purge { " PURGE" } else { "" },
|
||||||
|
)?;
|
||||||
|
if let Some(table_name) = table.as_ref() {
|
||||||
|
write!(f, " ON {}", table_name)?;
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Statement::DropFunction {
|
Statement::DropFunction {
|
||||||
if_exists,
|
if_exists,
|
||||||
func_desc,
|
func_desc,
|
||||||
|
|
|
@ -6255,6 +6255,11 @@ impl<'a> Parser<'a> {
|
||||||
loc
|
loc
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let table = if self.parse_keyword(Keyword::ON) {
|
||||||
|
Some(self.parse_object_name(false)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
Ok(Statement::Drop {
|
Ok(Statement::Drop {
|
||||||
object_type,
|
object_type,
|
||||||
if_exists,
|
if_exists,
|
||||||
|
@ -6263,6 +6268,7 @@ impl<'a> Parser<'a> {
|
||||||
restrict,
|
restrict,
|
||||||
purge,
|
purge,
|
||||||
temporary,
|
temporary,
|
||||||
|
table,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3987,3 +3987,34 @@ fn parse_straight_join() {
|
||||||
mysql()
|
mysql()
|
||||||
.verified_stmt("SELECT a.*, b.* FROM table_a STRAIGHT_JOIN table_b AS b ON a.b_id = b.id");
|
.verified_stmt("SELECT a.*, b.* FROM table_a STRAIGHT_JOIN table_b AS b ON a.b_id = b.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_drop_index() {
|
||||||
|
let sql = "DROP INDEX idx_name ON table_name";
|
||||||
|
match mysql().verified_stmt(sql) {
|
||||||
|
Statement::Drop {
|
||||||
|
object_type,
|
||||||
|
if_exists,
|
||||||
|
names,
|
||||||
|
cascade,
|
||||||
|
restrict,
|
||||||
|
purge,
|
||||||
|
temporary,
|
||||||
|
table,
|
||||||
|
} => {
|
||||||
|
assert!(!if_exists);
|
||||||
|
assert_eq!(ObjectType::Index, object_type);
|
||||||
|
assert_eq!(
|
||||||
|
vec!["idx_name"],
|
||||||
|
names.iter().map(ToString::to_string).collect::<Vec<_>>()
|
||||||
|
);
|
||||||
|
assert!(!cascade);
|
||||||
|
assert!(!restrict);
|
||||||
|
assert!(!purge);
|
||||||
|
assert!(!temporary);
|
||||||
|
assert!(table.is_some());
|
||||||
|
assert_eq!("table_name", table.unwrap().to_string());
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue