jiangzhx opened a new issue, #5791:
URL: https://github.com/apache/arrow-datafusion/issues/5791

   ### Describe the bug
   
   select a,b from t1 where (select count(*) from t2 where t1.a = t2.a)>0;
   
   logical_paln  unexpected  Aggregate: groupBy=[[t2.a]], 
aggr=[[COUNT(UInt8(1))]] 
   
   
   ```
   
+---------------+----------------------------------------------------------------------------------------------------------------------------+
   | plan_type     | plan                                                       
                                                                |
   
+---------------+----------------------------------------------------------------------------------------------------------------------------+
   | logical_plan  | Projection: t1.a, t1.b                                     
                                                                |
   |               |   Inner Join: t1.a = __scalar_sq_1.a                       
                                                                |
   |               |     TableScan: t1 projection=[a, b]                        
                                                                |
   |               |     SubqueryAlias: __scalar_sq_1                           
                                                                |
   |               |       Projection: t2.a                                     
                                                                |
   |               |         Filter: COUNT(UInt8(1)) > Int64(0)                 
                                                                |
   |               |           Aggregate: groupBy=[[t2.a]], 
aggr=[[COUNT(UInt8(1))]]                                                        
    |
   |               |             TableScan: t2 projection=[a]                   
                                                                |
   | physical_plan | ProjectionExec: expr=[a@0 as a, b@1 as b]                  
                                                                |
   |               |   CoalesceBatchesExec: target_batch_size=8192              
                                                                |
   |               |     HashJoinExec: mode=Partitioned, join_type=Inner, 
on=[(Column { name: "a", index: 0 }, Column { name: "a", index: 0 })] |
   |               |       CoalesceBatchesExec: target_batch_size=8192          
                                                                |
   |               |         RepartitionExec: partitioning=Hash([Column { name: 
"a", index: 0 }], 8), input_partitions=8                        |
   |               |           RepartitionExec: 
partitioning=RoundRobinBatch(8), input_partitions=1                             
                |
   |               |             MemoryExec: partitions=1, partition_sizes=[1]  
                                                                |
   |               |       ProjectionExec: expr=[a@0 as a]                      
                                                                |
   |               |         CoalesceBatchesExec: target_batch_size=8192        
                                                                |
   |               |           FilterExec: COUNT(UInt8(1))@1 > 0                
                                                                |
   |               |             AggregateExec: mode=FinalPartitioned, gby=[a@0 
as a], aggr=[COUNT(UInt8(1))]                                   |
   |               |               CoalesceBatchesExec: target_batch_size=8192  
                                                                |
   |               |                 RepartitionExec: partitioning=Hash([Column 
{ name: "a", index: 0 }], 8), input_partitions=8                |
   |               |                   AggregateExec: mode=Partial, gby=[a@0 as 
a], aggr=[COUNT(UInt8(1))]                                      |
   |               |                     RepartitionExec: 
partitioning=RoundRobinBatch(8), input_partitions=1                             
      |
   |               |                       MemoryExec: partitions=1, 
partition_sizes=[1]                                                        |
   |               |                                                            
                                                                |
   
+---------------+----------------------------------------------------------------------------------------------------------------------------+
   
   ```
   
   ### To Reproduce
   
   ```
   #[tokio::test]
   async fn test_count_wildcard_on_where_scalar_subquery() -> Result<()> {
       // you can find create_join_context() in  
datafusion/core/tests/dataframe.rs
       let ctx = create_join_context()?;
       ctx.sql("select a,b from t1 where (select count(*) from t2 where t1.a = 
t2.a)>0;")
           .await?
           .explain(false, false)?
           .show()
           .await?;
       Ok(())
   }
   ```
   
   ### Expected behavior
   
   _No response_
   
   ### 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]

Reply via email to