andygrove opened a new issue, #11570:
URL: https://github.com/apache/datafusion/issues/11570

   ### Is your feature request related to a problem or challenge?
   
   A common usage of `CASE WHEN` (particularly in the TPC-DS benchmark) is to 
protect against divide by zero errors. For example:
   
   ``sql
   CASE WHEN y > 0 THEN x / y ELSE null END
   ```
   
   The `CaseExpr` implementation is quite expensive and we could replace this 
whole expression with a divide kernel that returns null if the right hand side 
is zero (Rust has a `div_checked` function that already provides this 
functionality).
   
   arrow-rs already has the following code in `arrow-array/src/arithmetic.rs`, 
which is really close to what we need. I think we just need a version that 
returns an `Option::None` instead of an `Err`.
   
   ```rust
   #[inline]
   fn div_checked(self, rhs: Self) -> Result<Self, ArrowError> {
       if rhs.is_zero() {
           Err(ArrowError::DivideByZero)
       } else {
           self.checked_div(rhs).ok_or_else(|| {
               ArrowError::ComputeError(format!(
                   "Overflow happened on: {:?} / {:?}",
                   self, rhs
               ))
           })
       }
   }
   ```
   
   ### Describe the solution you'd like
   
   _No response_
   
   ### Describe alternatives you've considered
   
   _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: 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