epsio-banay opened a new issue, #12940:
URL: https://github.com/apache/datafusion/issues/12940

   ### Describe the bug
   
   Datafusion fails to plan a query that uses wildcard (*) in the distinct on 
select expressions fails, because it does not expand the wildcard expression 
inside DistinctOn. expansion should take place in ExpandWildcardRule analyze 
rule, but this rule only transforms Projection and SubqueryAlias logical plans. 
   
   ### To Reproduce
   
   Edit roundtrip_logical_plan_distinct_on test to use the query "SELECT 
DISTINCT ON (a % 2) * FROM t1 ORDER BY a % 2 DESC, b".
   
   then run the test.
   
   like so:
   ```
   #[tokio::test]
   async fn roundtrip_logical_plan_distinct_on() -> Result<()> {
       let ctx = SessionContext::new();
   
       let schema = Schema::new(vec![
           Field::new("a", DataType::Int64, true),
           Field::new("b", DataType::Decimal128(15, 2), true),
       ]);
   
       ctx.register_csv(
           "t1",
           "tests/testdata/test.csv",
           CsvReadOptions::default().schema(&schema),
       )
       .await?;
   
       let query = "SELECT DISTINCT ON (a % 2) * FROM t1 ORDER BY a % 2 DESC, 
b";
       let plan = ctx.sql(query).await?.into_optimized_plan()?;
   
       let bytes = logical_plan_to_bytes(&plan)?;
       let logical_round_trip = logical_plan_from_bytes(&bytes, &ctx)?;
       assert_eq!(format!("{plan}"), format!("{logical_round_trip}"));
   
       Ok(())
   }
   ```
   
   ### Expected behavior
   
   Wildcard expression should be expanded in ExpandWildcardRule and the query 
should be planned correctly.
   
   ### Additional context
   
   _No response_


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