Skip to content

Add GLOBAL context/modifier to SET statements #1767

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

Merged
merged 4 commits into from
Mar 20, 2025

Conversation

MohamedAbdeen21
Copy link
Contributor

Closes #1694

  • Add a GLOBAL variant to ContextModifier enum.
  • Replace local: bool field in SetVariable with a scope: ContextModifier.
  • Convenience impl From<Option<Keyword>> for ContextModifier
  • Update tests

src/ast/mod.rs Outdated
Comment on lines 7936 to 7947
impl From<Option<Keyword>> for ContextModifier {
fn from(kw: Option<Keyword>) -> Self {
match kw {
Some(kw) => match kw {
Keyword::LOCAL => Self::Local,
Keyword::SESSION => Self::Session,
Keyword::GLOBAL => Self::Global,
_ => Self::None,
},
None => Self::None,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can instead turn this into a regular function if the goal is to reuse it, since its not expected to be able to turn an arbitrary keyword into a ContextModifier.

Copy link
Contributor Author

@MohamedAbdeen21 MohamedAbdeen21 Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following. Instead of an impl From<Option<Keyword>> for ContextModifier you'd prefer a fn into_modifier(k: Option<Keyword>) -> ContextModifier?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly, essentially to put the logic in a function instead, maybe something more like?

fn context_modifier_from_keyword(kw: Keyword) -> Result<ContextModifier> {
}
// on the caller side if it has an option
modifier.map(context_modifier_from_keyword)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd still need to account for when the modifier var is a None. Unless you extract the None variant from ContextModifier and replace all ContextModifiers with options, which is a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would fn context_modifier_from_keyword(kw: Option<Keyword>) -> Result<ContextModifier> be fine to account for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, but at that point, what's the difference? Visibility, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

@mvzink mvzink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to me. I guess I didn't mention this in the issue, but the next thing to add for full MySQL support is to allow a separate scope for each variable in a Set::MultipleAssignments, i.e. adding a scope to SetAssignment. That will be a more substantial change to parsing itself and could be a separate PR IMO.

@MohamedAbdeen21
Copy link
Contributor Author

i.e. adding a scope to SetAssignment. That will be a more substantial change to parsing itself and could be a separate PR IMO.

I agree, it's gonna require moving some stuff around in the parse_set fn. I can start on that once we finalize this PR.

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @MohamedAbdeen21!
cc @alamb

@iffyio iffyio merged commit f487cbe into apache:main Mar 20, 2025
9 checks passed
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Apr 10, 2025
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

Successfully merging this pull request may close these issues.

Parse MySQL SET GLOBAL variables
3 participants