mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-24 16:04:04 +00:00
Remove PostgreSQL version of assert (#229)
Remove PostgreSQL procedural assert statement. This also simplifies code somewhat.
This commit is contained in:
parent
c24b0e01db
commit
583f22b929
3 changed files with 6 additions and 22 deletions
|
@ -555,8 +555,6 @@ pub enum Statement {
|
||||||
/// ASSERT <condition> [AS <message>]
|
/// ASSERT <condition> [AS <message>]
|
||||||
Assert {
|
Assert {
|
||||||
condition: Expr,
|
condition: Expr,
|
||||||
// AS or ,
|
|
||||||
separator: String,
|
|
||||||
message: Option<Expr>,
|
message: Option<Expr>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -818,15 +816,11 @@ impl fmt::Display for Statement {
|
||||||
write!(f, "ROLLBACK{}", if *chain { " AND CHAIN" } else { "" },)
|
write!(f, "ROLLBACK{}", if *chain { " AND CHAIN" } else { "" },)
|
||||||
}
|
}
|
||||||
Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name),
|
Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name),
|
||||||
Statement::Assert {
|
Statement::Assert { condition, message } => {
|
||||||
condition,
|
|
||||||
separator,
|
|
||||||
message,
|
|
||||||
} => {
|
|
||||||
write!(f, "ASSERT {}", condition)?;
|
write!(f, "ASSERT {}", condition)?;
|
||||||
|
|
||||||
if let Some(m) = message {
|
if let Some(m) = message {
|
||||||
write!(f, " {} {}", separator, m)?;
|
write!(f, " AS {}", m)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,19 +182,13 @@ impl Parser {
|
||||||
}
|
}
|
||||||
pub fn parse_assert(&mut self) -> Result<Statement, ParserError> {
|
pub fn parse_assert(&mut self) -> Result<Statement, ParserError> {
|
||||||
let condition = self.parse_expr()?;
|
let condition = self.parse_expr()?;
|
||||||
let (separator, message) = if self.consume_token(&Token::Comma) {
|
let message = if self.parse_keyword(Keyword::AS) {
|
||||||
(",".to_string(), Some(self.parse_expr()?))
|
Some(self.parse_expr()?)
|
||||||
} else if self.parse_keyword(Keyword::AS) {
|
|
||||||
("AS".to_string(), Some(self.parse_expr()?))
|
|
||||||
} else {
|
} else {
|
||||||
("".to_string(), None)
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Statement::Assert {
|
Ok(Statement::Assert { condition, message })
|
||||||
condition,
|
|
||||||
separator,
|
|
||||||
message,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an expression prefix
|
/// Parse an expression prefix
|
||||||
|
|
|
@ -1163,11 +1163,9 @@ fn parse_assert() {
|
||||||
match ast {
|
match ast {
|
||||||
Statement::Assert {
|
Statement::Assert {
|
||||||
condition: _condition,
|
condition: _condition,
|
||||||
separator,
|
|
||||||
message,
|
message,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(message, None);
|
assert_eq!(message, None);
|
||||||
assert_eq!(separator, "");
|
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@ -1184,9 +1182,7 @@ fn parse_assert_message() {
|
||||||
Statement::Assert {
|
Statement::Assert {
|
||||||
condition: _condition,
|
condition: _condition,
|
||||||
message: Some(message),
|
message: Some(message),
|
||||||
separator,
|
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(separator, "AS");
|
|
||||||
match message {
|
match message {
|
||||||
Expr::Value(Value::SingleQuotedString(s)) => assert_eq!(s, "No rows in table"),
|
Expr::Value(Value::SingleQuotedString(s)) => assert_eq!(s, "No rows in table"),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue