apache / apache/datafusion-sqlparser-rs

Optional GROUP BY statement

Open
#2,056 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
3.5k
Forks
772
Avg merge
4d 9h
Merged PRs (30d)
17

Description

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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the Select.group_by field returned through Parser::parse_sql and the parse_optional_group_by function mentioned in the issue. Determine how the parser represents an absent GROUP BY clause and whether the public API or its documentation needs to expose that distinction; done means the intended behavior is documented or covered by an appropriate parser test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.