phillipleblanc commented on code in PR #13006:
URL: https://github.com/apache/datafusion/pull/13006#discussion_r1807981408


##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -628,6 +629,17 @@ impl Unparser<'_> {
                     Arc::clone(&table_scan.source),
                     None,
                 )?;
+                // We will rebase the column references to the new alias if it 
exists.
+                // If the projection or filters are empty, we will append 
alias to the table scan.
+                //
+                // Example:
+                //   select t1.c1 from t1 where t1.c1 > 1 -> select a.c1 from 
t1 as a where a.c1 > 1
+                if alias.is_some()
+                    && (table_scan.projection.is_some() || 
!table_scan.filters.is_empty())
+                {
+                    builder = builder.alias(alias.clone().unwrap())?;
+                }
+

Review Comment:
   ```suggestion
                   if let Some(ref alias) = alias {
                       if table_scan.projection.is_some() || 
!table_scan.filters.is_empty() {
                           builder = builder.alias(alias.clone())?;
                       }
                   }
   ```
   
   I find this to be slightly cleaner



##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -677,6 +686,16 @@ impl Unparser<'_> {
                     builder = builder.limit(0, Some(fetch))?;
                 }
 
+                // If the table scan has an alias but no projection or 
filters, it means no column references are rebased.
+                // So we will append the alias to this subquery.
+                // Example:
+                //   select * from t1 limit 10 -> (select * from t1 limit 10) 
as a
+                if alias.is_some()
+                    && (table_scan.projection.is_none() && 
table_scan.filters.is_empty())
+                {
+                    builder = builder.alias(alias.clone().unwrap())?;
+                }

Review Comment:
   ```suggestion
                   if let Some(alias) = alias {
                       if table_scan.projection.is_some() || 
!table_scan.filters.is_empty() {
                           builder = builder.alias(alias)?;
                       }
                   }
   ```
   
   No need for a clone here.



-- 
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