goldmedal commented on code in PR #15068:
URL: https://github.com/apache/datafusion/pull/15068#discussion_r1987731975


##########
datafusion/core/tests/sql/select.rs:
##########
@@ -350,3 +351,48 @@ async fn test_version_function() {
 
     assert_eq!(version.value(0), expected_version);
 }
+
+#[tokio::test]
+async fn test_unparse_subqueryalias() -> Result<()> {

Review Comment:
   I prefer to remove this test and add another test in 
`datafusion/sql/tests/cases/plan_to_sql.rs`
   ```rust
   /// Test unparse the optimized plan from the following SQL:
   /// ```
   /// SELECT
   ///   customer_view.c_custkey,
   ///   customer_view.c_name,
   ///   customer_view.custkey_plus
   /// FROM
   ///   (
   ///     SELECT
   ///       customer.c_custkey,
   ///       customer.c_name,
   ///       customer.custkey_plus
   ///     FROM
   ///       (
   ///         SELECT
   ///           customer.c_custkey,
   ///           CAST(customer.c_custkey AS BIGINT) + 1 AS custkey_plus,
   ///           customer.c_name
   ///         FROM
   ///           (
   ///             SELECT
   ///               customer.c_custkey AS c_custkey,
   ///               customer.c_name AS c_name
   ///             FROM
   ///               customer
   ///           ) AS customer
   ///       ) AS customer
   ///   ) AS customer_view
   /// ```
   #[test]
   fn test_unparse_subquery_alias_with_table_pushdown() -> Result<()> {
       let schema = Schema::new(vec![
           Field::new("c_custkey", DataType::Int32, false),
           Field::new("c_name", DataType::Utf8, false),
       ]);
   
       let table_scan = table_scan(Some("customer"), &schema, Some(vec![0, 
1]))?.build()?;
   
       let plan = LogicalPlanBuilder::from(table_scan)
           .alias("customer")?
           .project(vec![
               col("customer.c_custkey"),
               cast(col("customer.c_custkey"), DataType::Int64)
                   .add(lit(1))
                   .alias("custkey_plus"),
               col("customer.c_name"),
           ])?
           .alias("customer")?
           .project(vec![
               col("customer.c_custkey"),
               col("customer.c_name"),
               col("customer.custkey_plus"),
           ])?
           .alias("customer_view")?
           .build()?;
   
       let unparser = Unparser::default();
       let sql = unparser.plan_to_sql(&plan)?;
       let expected = "SELECT customer_view.c_custkey, customer_view.c_name, 
customer_view.custkey_plus FROM (SELECT customer.c_custkey, 
(CAST(customer.c_custkey AS BIGINT) + 1) AS custkey_plus, customer.c_name FROM 
(SELECT customer.c_custkey, customer.c_name FROM customer AS customer) AS 
customer) AS customer_view";
       assert_eq!(sql.to_string(), expected);
       Ok(())
   }
   ```
   According to the previous discussion in 
https://github.com/apache/datafusion/pull/13267#issuecomment-2482503581, it's 
better to avoid making the unparsing test depend on the default optimizer. 
Instead, we can add a test, manually construct the expected optimized plan as 
the test case, and then try to unparse it.



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