apache / apache/datafusion-sqlparser-rs
Use identifiable structs for AST variant fields
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 17
Description
When consuming the generated AST for further processing, one needs to match against and deconstruct `ast::Statement` instances. Currently, the fields of this enum's variants are defined inline... which makes it impossible for downstream code to represent the nested structures as types. For example, consider this structure:
https://github.com/ballista-compute/sqlparser-rs/blob/35ef0eee3857c59827b2587bc813218a00dce264/src/ast/mod.rs#L490-L497
I propose we migrate to the following pattern.
```rust
pub struct AnalyzeStatement {
table_name: ObjectName,
partitions: Option>,
for_columns: bool,
....
}
pub enum Statement {
Analyze(AnalyzeStatement),
...
}
```
Obviously this is a massive breaking change, but that seems OK given the `0.9.x` crates.io version.
Thoughts?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the Statement enum and related definitions in src/ast/mod.rs, especially the linked lines around 490-497. Assess how each inline variant field could become an identifiable struct while preserving the proposed AST shape. Done means the relevant AST variants use named structs and the resulting breaking API change is consistently applied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100