You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2024/11/15 18:51:57 UTC
Re: [PR] fix: Remove dangling table references in `unparser` [datafusion]
alamb commented on code in PR #13405:
URL: https://github.com/apache/datafusion/pull/13405#discussion_r1844319438
##########
datafusion/sql/src/unparser/rewrite.rs:
##########
@@ -363,3 +363,138 @@ impl TreeNodeRewriter for TableAliasRewriter<'_> {
}
}
}
+
+/// Takes an input list of identifiers and a list of identifiers that are available from relations or joins.
+/// Removes any table identifiers that are not present in the list of available identifiers, retains original column names.
+pub fn remove_dangling_identifiers(idents: &mut Vec<Ident>, available_idents: &[String]) {
Review Comment:
I don't understand this code super deeply, but this seems to me like it is treating the symptom (incorrect qualifiers) rather than the root cause.
Specifically, did you look into fixing the code so that it didn't create incorrect indentifiers in the first place, rather than trying to modify the created AST after the fact to remove incorrect indentifers ?
##########
datafusion/sql/src/unparser/ast.rs:
##########
@@ -360,6 +455,23 @@ impl RelationBuilder {
pub fn has_relation(&self) -> bool {
self.relation.is_some()
}
+ pub fn get_name(&self) -> Option<&ast::ObjectName> {
+ match self.relation {
+ Some(TableFactorBuilder::Table(ref value)) => value.name.as_ref(),
+ _ => None,
+ }
+ }
+ pub fn get_alias(&self) -> Option<String> {
Review Comment:
You can probably avoid a bunch of copies if you made this return a reference to a `&str` rather than a `String` -- if the caller needed the string they can always copy it.
```suggestion
pub fn get_alias(&self) -> Option<&str> {
```
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -158,10 +158,12 @@ impl Unparser<'_> {
}
let mut twj = select_builder.pop_from().unwrap();
- twj.relation(relation_builder);
+ twj.relation(relation_builder.clone());
Review Comment:
I don't understand why this needs to have a clone now 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org