You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Kimishu (via GitHub)" <gi...@apache.org> on 2025/10/06 09:52:56 UTC
[I] Optional GROUP BY statement [datafusion-sqlparser-rs]
Kimishu opened a new issue, #2056:
URL: https://github.com/apache/datafusion-sqlparser-rs/issues/2056
Working on my custom sql validation, I needed somehow to check, does user provide group_by/limit+offset/sort_by clauses.
I got smth like this and found `.group_by` field as non-optional. Is it right?
```rust
let wrong_query = "SELECT * FROM example_table GROUP BY example_field";
//Parser returns success(!) below
if let Statement::Query(q) = Parser::parse_sql(&GenericDialect {}, &query)?.first().unwrap() {
if q.limit_clause.is_none() {...}
if q.order_by.is_none() {...}
let select_query = query.body.as_select().unwrap();
//And I expected smth like this:
if select_query.group_by.is_none() {...}
}
```
Maybe I'm doing smth wrong and there is a proper and faster way for that?
Also I noticed a `parse_optional_group_by` fn but I didn't get how to use it., there is no info nor examples in docs about it. Looks like it's inner fn?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Optional GROUP BY statement [datafusion-sqlparser-rs]
Posted by "LucaCappelletti94 (via GitHub)" <gi...@apache.org>.
LucaCappelletti94 closed issue #2056: Optional GROUP BY statement
URL: https://github.com/apache/datafusion-sqlparser-rs/issues/2056
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Optional GROUP BY statement [datafusion-sqlparser-rs]
Posted by "LucaCappelletti94 (via GitHub)" <gi...@apache.org>.
LucaCappelletti94 commented on issue #2056:
URL: https://github.com/apache/datafusion-sqlparser-rs/issues/2056#issuecomment-5867887554
`Select.group_by` is a `GroupByExpr`, and a query without `GROUP BY` parses to `GroupByExpr::Expressions` with two empty lists. Check `matches!(select.group_by, GroupByExpr::Expressions(ref e, _) if e.is_empty())` to detect a missing clause. Closing as answered.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org