-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: preserve qualifiers when rewriting expressions #12341
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 | ||
---|---|---|---|---|
|
@@ -303,9 +303,11 @@ pub struct NamePreserver { | |||
use_alias: bool, | ||||
} | ||||
|
||||
type QualifiedName = (Option<TableReference>, String); | ||||
|
||||
/// If the name of an expression is remembered, it will be preserved when | ||||
/// rewriting the expression | ||||
pub struct SavedName(Option<String>); | ||||
pub struct SavedName(Option<QualifiedName>); | ||||
|
||||
impl NamePreserver { | ||||
/// Create a new NamePreserver for rewriting the `expr` that is part of the specified plan | ||||
|
@@ -326,7 +328,7 @@ impl NamePreserver { | |||
|
||||
pub fn save(&self, expr: &Expr) -> Result<SavedName> { | ||||
let original_name = if self.use_alias { | ||||
Some(expr.name_for_alias()?) | ||||
Some(expr.qualified_name()) | ||||
} else { | ||||
None | ||||
}; | ||||
|
@@ -336,12 +338,14 @@ impl NamePreserver { | |||
} | ||||
|
||||
impl SavedName { | ||||
/// Ensures the name of the rewritten expression is preserved | ||||
/// Ensures the qualified name of the rewritten expression is preserved | ||||
pub fn restore(self, expr: Expr) -> Result<Expr> { | ||||
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. The return value no longer needs |
||||
let Self(original_name) = self; | ||||
match original_name { | ||||
Some(name) => expr.alias_if_changed(name), | ||||
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 seems like we could potentially also remove The only other use of it seems to be in
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.
|
||||
None => Ok(expr), | ||||
Some(old_name) if expr.qualified_name() != old_name => { | ||||
Ok(expr.alias_qualified(old_name.0, old_name.1)) | ||||
} | ||||
_ => Ok(expr), | ||||
} | ||||
} | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally suggest creating an enum to make this more explicit (rather than two level of options)-- perhaps something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.