Add fn support_group_by_expr to Dialect trait (#896)

This commit is contained in:
Jeremy Dyer 2023-06-15 09:10:56 -04:00 committed by GitHub
parent 2b37e4ae6e
commit 2296de2bc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 1 deletions

View file

@ -28,4 +28,8 @@ impl Dialect for DuckDbDialect {
fn supports_filter_during_aggregation(&self) -> bool {
true
}
fn supports_group_by_expr(&self) -> bool {
true
}
}

View file

@ -28,4 +28,8 @@ impl Dialect for GenericDialect {
|| ch == '#'
|| ch == '_'
}
fn supports_group_by_expr(&self) -> bool {
true
}
}

View file

@ -113,6 +113,10 @@ pub trait Dialect: Debug + Any {
fn supports_within_after_array_aggregation(&self) -> bool {
false
}
/// Returns true if the dialects supports `group sets, roll up, or cube` expressions.
fn supports_group_by_expr(&self) -> bool {
false
}
/// Dialect-specific prefix parser override
fn parse_prefix(&self, _parser: &mut Parser) -> Option<Result<Expr, ParserError>> {
// return None to fall back to the default behavior

View file

@ -42,6 +42,10 @@ impl Dialect for PostgreSqlDialect {
fn supports_filter_during_aggregation(&self) -> bool {
true
}
fn supports_group_by_expr(&self) -> bool {
true
}
}
pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {

View file

@ -975,7 +975,7 @@ impl<'a> Parser<'a> {
/// parse a group by expr. a group by expr can be one of group sets, roll up, cube, or simple
/// expr.
fn parse_group_by_expr(&mut self) -> Result<Expr, ParserError> {
if dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect) {
if self.dialect.supports_group_by_expr() {
if self.parse_keywords(&[Keyword::GROUPING, Keyword::SETS]) {
self.expect_token(&Token::LParen)?;
let result = self.parse_comma_separated(|p| p.parse_tuple(false, true))?;