mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-25 16:34:04 +00:00
Support parsing multiple show variables. (#290)
* feat: support parsing multiple show variables. * fix: fix fmt error
This commit is contained in:
parent
f40955ee82
commit
07342d5853
3 changed files with 26 additions and 7 deletions
|
@ -637,7 +637,7 @@ pub enum Statement {
|
||||||
/// SHOW <variable>
|
/// SHOW <variable>
|
||||||
///
|
///
|
||||||
/// Note: this is a PostgreSQL-specific statement.
|
/// Note: this is a PostgreSQL-specific statement.
|
||||||
ShowVariable { variable: Ident },
|
ShowVariable { variable: Vec<Ident> },
|
||||||
/// SHOW COLUMNS
|
/// SHOW COLUMNS
|
||||||
///
|
///
|
||||||
/// Note: this is a MySQL-specific statement.
|
/// Note: this is a MySQL-specific statement.
|
||||||
|
@ -1136,7 +1136,13 @@ impl fmt::Display for Statement {
|
||||||
value = display_comma_separated(value)
|
value = display_comma_separated(value)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
|
Statement::ShowVariable { variable } => {
|
||||||
|
write!(f, "SHOW")?;
|
||||||
|
if !variable.is_empty() {
|
||||||
|
write!(f, " {}", display_separated(variable, " "))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Statement::ShowColumns {
|
Statement::ShowColumns {
|
||||||
extended,
|
extended,
|
||||||
full,
|
full,
|
||||||
|
|
|
@ -2043,6 +2043,19 @@ impl<'a> Parser<'a> {
|
||||||
Ok(ObjectName(idents))
|
Ok(ObjectName(idents))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse identifiers
|
||||||
|
pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError> {
|
||||||
|
let mut idents = vec![];
|
||||||
|
loop {
|
||||||
|
match self.next_token() {
|
||||||
|
Token::Word(w) => idents.push(w.to_ident()),
|
||||||
|
Token::EOF => break,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(idents)
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a simple one-word identifier (possibly quoted, possibly a keyword)
|
/// Parse a simple one-word identifier (possibly quoted, possibly a keyword)
|
||||||
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError> {
|
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError> {
|
||||||
match self.next_token() {
|
match self.next_token() {
|
||||||
|
@ -2439,7 +2452,7 @@ impl<'a> Parser<'a> {
|
||||||
self.parse_show_columns()
|
self.parse_show_columns()
|
||||||
} else {
|
} else {
|
||||||
Ok(Statement::ShowVariable {
|
Ok(Statement::ShowVariable {
|
||||||
variable: self.parse_identifier()?,
|
variable: self.parse_identifiers()?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,19 +443,19 @@ fn parse_set() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_show() {
|
fn parse_show() {
|
||||||
let stmt = pg_and_generic().verified_stmt("SHOW a");
|
let stmt = pg_and_generic().verified_stmt("SHOW a a");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stmt,
|
stmt,
|
||||||
Statement::ShowVariable {
|
Statement::ShowVariable {
|
||||||
variable: "a".into()
|
variable: vec!["a".into(), "a".into()]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let stmt = pg_and_generic().verified_stmt("SHOW ALL");
|
let stmt = pg_and_generic().verified_stmt("SHOW ALL ALL");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stmt,
|
stmt,
|
||||||
Statement::ShowVariable {
|
Statement::ShowVariable {
|
||||||
variable: "ALL".into()
|
variable: vec!["ALL".into(), "ALL".into()]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue