Skip to content

Use identifiable structs for AST variant fields #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cmoog opened this issue Jun 3, 2021 · 8 comments
Open

Use identifiable structs for AST variant fields #311

cmoog opened this issue Jun 3, 2021 · 8 comments

Comments

@cmoog
Copy link

cmoog commented Jun 3, 2021

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.

pub struct AnalyzeStatement {
  table_name: ObjectName, 
  partitions: Option<Vec<Expr>>, 
  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?

@alamb
Copy link
Contributor

alamb commented Aug 20, 2021

Is the primary usecase of this proposal so that downstream code can re-use AnalyzeStatement directly?

@cmoog
Copy link
Author

cmoog commented Aug 20, 2021

Is the primary usecase of this proposal so that downstream code can re-use AnalyzeStatement directly?

Yes, exactly.

@tvallotton
Copy link
Contributor

I totally agree with this proposal. This would simplify my code considerably. I've got structs that are complete translations of some enum variants.

@tvallotton
Copy link
Contributor

I forked the project and made those changes if you want to see how it would look.

@alamb
Copy link
Contributor

alamb commented Sep 9, 2021

I don't feel qualified to approve / accept this level of change without some additional buy in from @nickolay / @andygrove / @Dandandan . #311 (comment) seems like a good usecase to me but it is a pretty major change for all users of sqlparser-rs.

@nickolay
Copy link
Contributor

#40 could be marked as a duplicate of this issue as well. As mentioned there, I didn't think creating a separate struct for every single variant (even those holding one or two fields) of every enum was worth the breakage, but extracting complex variants like Statement::Analyze is something we have done before.

In #315 (comment) @Dandandan suggested doing this for all variants of the Statement enum, which seems a sensible suggestion too, as most statements exceed the complexity threshold anyway.

@alamb
Copy link
Contributor

alamb commented Dec 12, 2021

Your guidance makes a lot of sense to me @nickolay -- thank you

@alamb
Copy link
Contributor

alamb commented Feb 8, 2022

Sadly I don't have the time to help drive projects such as this. Unless one of the other maintainers wants to do so, PRs like this are not likely to be merged. I am sorry I don't have the time and I am sorry if your time was wasted.

As the current state of affairs might not have been clear in the project's README. I have added #416 to try and help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants