mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-10 07:56:20 +00:00
Support EXCLUDE support for snowflake and generic dialect (#721)
The exclude clause can be used after a possibly qualified on SELECT
This commit is contained in:
parent
3df0e444c8
commit
fa6bd01b19
7 changed files with 170 additions and 21 deletions
|
@ -5423,11 +5423,49 @@ impl<'a> Parser<'a> {
|
|||
None => SelectItem::UnnamedExpr(expr),
|
||||
})
|
||||
}
|
||||
WildcardExpr::QualifiedWildcard(prefix) => Ok(SelectItem::QualifiedWildcard(prefix)),
|
||||
WildcardExpr::Wildcard => Ok(SelectItem::Wildcard),
|
||||
WildcardExpr::QualifiedWildcard(prefix) => {
|
||||
let opt_exclude = if dialect_of!(self is GenericDialect | SnowflakeDialect) {
|
||||
self.parse_optional_select_item_exclude()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(SelectItem::QualifiedWildcard(prefix, opt_exclude))
|
||||
}
|
||||
WildcardExpr::Wildcard => {
|
||||
let opt_exclude = if dialect_of!(self is GenericDialect | SnowflakeDialect) {
|
||||
self.parse_optional_select_item_exclude()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(SelectItem::Wildcard(opt_exclude))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse an [`Exclude`](ExcludeSelectItem) information for wildcard select items.
|
||||
///
|
||||
/// If it is not possible to parse it, will return an option.
|
||||
pub fn parse_optional_select_item_exclude(
|
||||
&mut self,
|
||||
) -> Result<Option<ExcludeSelectItem>, ParserError> {
|
||||
let opt_exclude = if self.parse_keyword(Keyword::EXCLUDE) {
|
||||
if self.consume_token(&Token::LParen) {
|
||||
let columns = self.parse_comma_separated(|parser| parser.parse_identifier())?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Some(ExcludeSelectItem::Multiple(columns))
|
||||
} else {
|
||||
let column = self.parse_identifier()?;
|
||||
Some(ExcludeSelectItem::Single(column))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(opt_exclude)
|
||||
}
|
||||
|
||||
/// Parse an expression, optionally followed by ASC or DESC (used in ORDER BY)
|
||||
pub fn parse_order_by_expr(&mut self) -> Result<OrderByExpr, ParserError> {
|
||||
let expr = self.parse_expr()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue