joseph-isaacs opened a new issue, #13244:
URL: https://github.com/apache/datafusion/issues/13244

   ### Is your feature request related to a problem or challenge?
   
   I am trying to use `PruningPredicate`s. 
   
   The expressions require coercion `ExprSimplifier::coerce` before it can be 
evaluated, so we run [`simplify`, `coerce`, `simplify`, `create_physical_expr`, 
`PruningPredicate::try_new`].
   
   If the expression being considered (with schema) is: `Col('y', Int32) = 
Lit(Int64(5))` then the resulting expression will be.
   ```
   BinaryExpr {
       left: Cast(
           Cast {
               expr: Column(
                   Column {
                       relation: None,
                       name: "y",
                   },
               ),
               data_type: Int64,
           },
       ),
       op: Eq,
       right: Literal(
           Int64(5),
       ),
   }
   ```
   
   Then when `PruningPredicate` analysis is run the `LiteralGuarantee::analyze` 
will not find any `LiteralGuarantee`s and therefore pruning will safely assume 
that nothing can be pruned. 
   
   However if the expression is `Col('y', Int32) = Lit(Int32(5))`, no cast will 
be included and pruning will work as indented.
   
   ### Describe the solution you'd like
   
   Either:
    - expand `LiteralGuarantee::analyze` to understand `Cast`ing
    - extend `ExprSimplifier::coerce` to safely downcast Literals (in `Lit <op> 
Col`) to the column type if possible `Lit(Int64(2)) -> Lit(Int16(2))`.
    - or add another pass to downcast all literals (where lossless) so that 
coercion is applied to the literal and therefore folded into the literal.
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   Relevant issues: https://github.com/apache/datafusion/issues/8302


-- 
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: github-unsubscr...@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to