adriangb commented on PR #12606:
URL: https://github.com/apache/datafusion/pull/12606#issuecomment-2379279428

   Here's an example:
   
   ```rust
   use std::sync::Arc;
   
   use arrow_schema::{DataType, Field, Schema};
   use datafusion::{common::DFSchema, 
physical_optimizer::pruning::PruningPredicate, prelude::*};
   
   fn main() {
       let sql = "col = ANY([1, 2])";
       let ctx = SessionContext::new();
       let schema = Arc::new(Schema::new(vec![Field::new("col", 
DataType::Int32, true)]));
       let df_schema = DFSchema::try_from(schema.clone()).unwrap();
   
       // An expression that PruningPredicate doesn't understand becomes `true`
       let expr = ctx.parse_sql_expr(sql, &df_schema).unwrap();
       println!("expr: {:?}", expr);
       let phys_expr = ctx.create_physical_expr(expr, &df_schema).unwrap();
       println!("phys_expr: {:?}", phys_expr);
       let pruning = PruningPredicate::try_new(phys_expr, 
schema.clone()).unwrap();
       let pruning_expr = pruning.predicate_expr().clone();
       println!("pruning_expr: {:?}", pruning_expr);
       // pruning_expr: Literal { value: Boolean(true) }
   
       // An expression referencing columns that don't have statistics 
collected (i.e. aren't int the schema)
       // causes an Err
       let expr = ctx.parse_sql_expr("other = 1", &df_schema).unwrap();
       println!("expr: {:?}", expr);
       let phys_expr = ctx.create_physical_expr(expr, &df_schema).unwrap();
       println!("phys_expr: {:?}", phys_expr);
       PruningPredicate::try_new(phys_expr, schema.clone()).unwrap();
       // SchemaError(FieldNotFound { field: Column { relation: None, name: 
"other" }, valid_fields: [Column { relation: None, name: "col" }] }, Some(""))
   }
   ```
   
   If I do the rewrite before PruningPredicate then I end up with just `true`.


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