yjerry-fortinet opened a new issue, #20083:
URL: https://github.com/apache/datafusion/issues/20083

   ### Describe the bug
   
   optimize failed if a plan with filter: ` Filter: EXISTS (<subquery>) OR 
EXISTS (<subquery>)`
   
   ### To Reproduce
   
   ```
   use datafusion::logical_expr::expr::Exists;
   use datafusion::logical_expr::utils::disjunction;
   use datafusion::logical_expr::{LogicalPlan, LogicalPlanBuilder, TableSource};
   use datafusion::optimizer::{Optimizer, OptimizerContext, OptimizerRule};
   use datafusion::prelude::{Expr, lit};
   use datafusion::{
       arrow::datatypes::{DataType, Field, Schema},
       datasource::{DefaultTableSource, MemTable},
   };
   use datafusion_common::{Column, JoinType};
   use std::sync::Arc;
   
   async fn get_table() -> datafusion_common::Result<Arc<dyn TableSource>> {
       let schema = Arc::new(Schema::new(vec![
           Field::new("uid", DataType::Int32, false),
           Field::new("val", DataType::Int32, false),
       ]));
       let provider = MemTable::try_new(schema.clone(), vec![vec![]])?;
       let table = Arc::new(DefaultTableSource::new(Arc::new(provider)));
   
       Ok(table)
   }
   
   async fn build_exists_expr(table_name: &str) -> 
datafusion_common::Result<Expr> {
       let table = get_table().await?;
   
       let scan = LogicalPlanBuilder::scan(table_name, table.clone(), None)?
           .project(vec![lit(1)])?
           .build()?;
   
       let subquery = datafusion::logical_expr::Subquery {
           subquery: Arc::new(scan),
           outer_ref_columns: vec![],
           spans: Default::default(),
       };
   
       Ok(Expr::Exists(Exists::new(subquery, false)))
   }
   
   async fn build_plan() -> datafusion_common::Result<LogicalPlan> {
       let exists_a = build_exists_expr("a").await?;
       let exists_b = build_exists_expr("b").await?;
   
       let filter = disjunction(vec![exists_a, exists_b]);
   
       let mut scan_a =
           LogicalPlanBuilder::scan("a", get_table().await?, 
None)?.filter(filter.unwrap())?;
       
       // scan_a = 
scan_a.project(vec![Expr::Column(Column::from_name("uid"))])?;
       
       let scan_b = LogicalPlanBuilder::scan("b", get_table().await?, 
None)?.build()?;
   
       let plan = scan_a
           .join(
               scan_b,
               JoinType::Left,
               (vec!["uid".to_string()], vec!["uid".to_string()]),
               None,
           )?
           .build()?;
   
       let optimizer = Optimizer::new();
       let config = OptimizerContext::new().with_max_passes(16);
       let ret = optimizer.optimize(plan, &config, observer);
       if ret.is_err() {
           println!("ret = {:#?}", ret);
       }
   
       fn observer(plan: &LogicalPlan, rule: &dyn OptimizerRule) {
           println!(
               "\nAfter applying rule '{}':\n{}",
               rule.name(),
               plan.display_indent()
           )
       }
   
       ret
   }
   
   
   #[tokio::test]
   async fn test_build_plan() {
       let ret = build_plan().await;
       assert!(ret.is_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]


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

Reply via email to