-
Notifications
You must be signed in to change notification settings - Fork 711
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ use serde::{Deserialize, Serialize}; | |
| #[cfg(feature = "visitor")] | ||
| use sqlparser_derive::{Visit, VisitMut}; | ||
|
|
||
| use crate::tokenizer::Span; | ||
| use crate::{keywords::Keyword, tokenizer::Span}; | ||
|
|
||
| pub use self::data_type::{ | ||
| ArrayElemTypeDef, BinaryLength, CharLengthUnits, CharacterLength, DataType, EnumMember, | ||
|
|
@@ -2578,7 +2578,7 @@ pub enum Set { | |
| /// SQL Standard-style | ||
| /// SET a = 1; | ||
| SingleAssignment { | ||
| local: bool, | ||
| scope: ContextModifier, | ||
| hivevar: bool, | ||
| variable: ObjectName, | ||
| values: Vec<Expr>, | ||
|
|
@@ -2660,7 +2660,7 @@ impl Display for Set { | |
| role_name, | ||
| } => { | ||
| let role_name = role_name.clone().unwrap_or_else(|| Ident::new("NONE")); | ||
| write!(f, "SET{context_modifier} ROLE {role_name}") | ||
| write!(f, "SET {context_modifier}ROLE {role_name}") | ||
| } | ||
| Self::SetSessionParam(kind) => write!(f, "SET {kind}"), | ||
| Self::SetTransaction { | ||
|
|
@@ -2707,15 +2707,15 @@ impl Display for Set { | |
| Ok(()) | ||
| } | ||
| Set::SingleAssignment { | ||
| local, | ||
| scope, | ||
| hivevar, | ||
| variable, | ||
| values, | ||
| } => { | ||
| write!( | ||
| f, | ||
| "SET {}{}{} = {}", | ||
| if *local { "LOCAL " } else { "" }, | ||
| scope, | ||
| if *hivevar { "HIVEVAR:" } else { "" }, | ||
| variable, | ||
| display_comma_separated(values) | ||
|
|
@@ -7910,6 +7910,8 @@ pub enum ContextModifier { | |
| Local, | ||
| /// `SESSION` identifier | ||
| Session, | ||
| /// `GLOBAL` identifier | ||
| Global, | ||
| } | ||
|
|
||
| impl fmt::Display for ContextModifier { | ||
|
|
@@ -7919,11 +7921,28 @@ impl fmt::Display for ContextModifier { | |
| write!(f, "") | ||
| } | ||
| Self::Local => { | ||
| write!(f, " LOCAL") | ||
| write!(f, "LOCAL ") | ||
| } | ||
| Self::Session => { | ||
| write!(f, " SESSION") | ||
| write!(f, "SESSION ") | ||
| } | ||
| Self::Global => { | ||
| write!(f, "GLOBAL ") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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, | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not following. Instead of an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, but at that point, what's the difference? Visibility, maybe?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.