Skip to content

Commit 2296de2

Browse files
authored
Add fn support_group_by_expr to Dialect trait (apache#896)
1 parent 2b37e4a commit 2296de2

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

src/dialect/duckdb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ impl Dialect for DuckDbDialect {
2828
fn supports_filter_during_aggregation(&self) -> bool {
2929
true
3030
}
31+
32+
fn supports_group_by_expr(&self) -> bool {
33+
true
34+
}
3135
}

src/dialect/generic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ impl Dialect for GenericDialect {
2828
|| ch == '#'
2929
|| ch == '_'
3030
}
31+
32+
fn supports_group_by_expr(&self) -> bool {
33+
true
34+
}
3135
}

src/dialect/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ pub trait Dialect: Debug + Any {
113113
fn supports_within_after_array_aggregation(&self) -> bool {
114114
false
115115
}
116+
/// Returns true if the dialects supports `group sets, roll up, or cube` expressions.
117+
fn supports_group_by_expr(&self) -> bool {
118+
false
119+
}
116120
/// Dialect-specific prefix parser override
117121
fn parse_prefix(&self, _parser: &mut Parser) -> Option<Result<Expr, ParserError>> {
118122
// return None to fall back to the default behavior

src/dialect/postgresql.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ impl Dialect for PostgreSqlDialect {
4242
fn supports_filter_during_aggregation(&self) -> bool {
4343
true
4444
}
45+
46+
fn supports_group_by_expr(&self) -> bool {
47+
true
48+
}
4549
}
4650

4751
pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {

src/parser.rs

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

0 commit comments

Comments
 (0)