mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-17 05:48:35 +00:00
MySQL: support for GROUP_CONCAT() (#1256)
This commit is contained in:
parent
d9d69a2192
commit
c36e617d61
4 changed files with 23 additions and 0 deletions
|
|
@ -4962,6 +4962,10 @@ pub enum FunctionArgumentClause {
|
|||
///
|
||||
/// See <https://trino.io/docs/current/functions/aggregate.html>.
|
||||
OnOverflow(ListAggOnOverflow),
|
||||
/// The `SEPARATOR` clause to the [`GROUP_CONCAT`] function in MySQL.
|
||||
///
|
||||
/// [`GROUP_CONCAT`]: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat
|
||||
Separator(Value),
|
||||
}
|
||||
|
||||
impl fmt::Display for FunctionArgumentClause {
|
||||
|
|
@ -4975,6 +4979,7 @@ impl fmt::Display for FunctionArgumentClause {
|
|||
}
|
||||
FunctionArgumentClause::Limit(limit) => write!(f, "LIMIT {limit}"),
|
||||
FunctionArgumentClause::OnOverflow(on_overflow) => write!(f, "{on_overflow}"),
|
||||
FunctionArgumentClause::Separator(sep) => write!(f, "SEPARATOR {sep}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -616,6 +616,7 @@ define_keywords!(
|
|||
SELECT,
|
||||
SEMI,
|
||||
SENSITIVE,
|
||||
SEPARATOR,
|
||||
SEQUENCE,
|
||||
SEQUENCEFILE,
|
||||
SEQUENCES,
|
||||
|
|
|
|||
|
|
@ -9488,6 +9488,12 @@ impl<'a> Parser<'a> {
|
|||
clauses.push(FunctionArgumentClause::Limit(self.parse_expr()?));
|
||||
}
|
||||
|
||||
if dialect_of!(self is GenericDialect | MySqlDialect)
|
||||
&& self.parse_keyword(Keyword::SEPARATOR)
|
||||
{
|
||||
clauses.push(FunctionArgumentClause::Separator(self.parse_value()?));
|
||||
}
|
||||
|
||||
if let Some(on_overflow) = self.parse_listagg_on_overflow()? {
|
||||
clauses.push(FunctionArgumentClause::OnOverflow(on_overflow));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2706,3 +2706,14 @@ fn parse_json_table() {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_group_concat() {
|
||||
// examples taken from mysql docs
|
||||
// https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat
|
||||
mysql_and_generic().verified_expr("GROUP_CONCAT(DISTINCT test_score)");
|
||||
mysql_and_generic().verified_expr("GROUP_CONCAT(test_score ORDER BY test_score)");
|
||||
mysql_and_generic().verified_expr("GROUP_CONCAT(test_score SEPARATOR ' ')");
|
||||
mysql_and_generic()
|
||||
.verified_expr("GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue