peasee commented on code in PR #13405:
URL: https://github.com/apache/datafusion/pull/13405#discussion_r1841601617


##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -157,10 +157,95 @@ impl Unparser<'_> {
             )]);
         }
 
+        // Construct a list of all the identifiers present in query sources
+        let mut all_idents = Vec::new();
+        if let Some(source_alias) = relation_builder.get_alias() {
+            all_idents.push(source_alias);
+        } else if let Some(source_name) = relation_builder.get_name() {
+            let full_ident = source_name.to_string();
+            if let Some(name) = source_name.0.last() {
+                if full_ident != name.to_string() {
+                    // supports identifiers that contain the entire path, as 
well as just the end table leaf
+                    // like catalog.schema.table and table
+                    all_idents.push(name.to_string());
+                }
+            }
+            all_idents.push(full_ident);
+        }
+
         let mut twj = select_builder.pop_from().unwrap();
+        twj.get_joins()
+            .iter()
+            .for_each(|join| match &join.relation {
+                ast::TableFactor::Table { alias, name, .. } => {
+                    if let Some(alias) = alias {
+                        all_idents.push(alias.name.to_string());
+                    } else {
+                        let full_ident = name.to_string();
+                        if let Some(name) = name.0.last() {
+                            if full_ident != name.to_string() {
+                                // supports identifiers that contain the 
entire path, as well as just the end table leaf
+                                // like catalog.schema.table and table
+                                all_idents.push(name.to_string());
+                            }
+                        }
+                        all_idents.push(full_ident);
+                    }
+                }
+                ast::TableFactor::Derived {
+                    alias: Some(alias), ..
+                } => {
+                    all_idents.push(alias.name.to_string());
+                }
+                _ => {}
+            });
+
         twj.relation(relation_builder);
         select_builder.push_from(twj);
 
+        // Ensure that the projection contains references to sources that 
actually exist
+        let mut projection = select_builder.get_projection();

Review Comment:
   I've moved it into select builder! A little cleaner now, thanks 😄 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to