carlosahs commented on issue #15916:
URL: https://github.com/apache/datafusion/issues/15916#issuecomment-3747866093

   Hi. I think I get the gist of things now. Currently working on adding a new 
`ceil` module in 
https://github.com/apache/datafusion/blob/main/datafusion/spark/src/function/math/mod.rs.
 @shehabgamin, I've got some questions regarding this [code 
block](https://github.com/lakehq/sail/blob/2c5f16716df5dde04280c1525a33b6d6ef45a249/crates/sail-function/src/scalar/math/spark_ceil_floor.rs#L99-L122):
   
   ```rust
               let (precision, scale) = match expr {
                   DataType::Int8 => Ok((3, 0)),
                   DataType::UInt8 | DataType::Int16 => Ok((5, 0)),
                   DataType::UInt16 | DataType::Int32 => Ok((10, 0)),
                   DataType::UInt32 | DataType::UInt64 | DataType::Int64 => 
Ok((20, 0)),
                   DataType::Float32 => Ok((14, 7)),
                   DataType::Float64 => Ok((30, 15)),
                   DataType::Decimal128(precision, scale) | 
DataType::Decimal256(precision, scale) => {
                       if *precision <= DECIMAL128_MAX_PRECISION && *scale <= 
DECIMAL128_MAX_SCALE {
                           Ok((*precision as i32, *scale as i32))
                       } else {
                           Err(unsupported_data_type_exec_err(
                               name,
                               format!("Decimal Type must have precision <= 
{DECIMAL128_MAX_PRECISION} and scale <= {DECIMAL128_MAX_SCALE}").as_str(),
                               arg_fields[0].data_type(),
                           ))
                       }
                   }
                   _ => Err(unsupported_data_type_exec_err(
                       name,
                       "Numeric Type for expr",
                       expr,
                   )),
               }?;
   ```
   
   1. For the integer types, we set the precision to the minimum power of 10 
that contains all of the bits, right? So, `Int8 => Ok((3, 0))` because 10^3 = 
1000, 2^8 = 256 and 1000 >= 256. But then we have `UInt8` mapped to `Ok((5, 
0))`, is there a particular reason why powers of 10 for unsigned integers need 
to match with the powers of 10 for signed integers that double their bits, 
i.e., `UInt8` and `Int16` share 5 exponent, `UInt16` and `Int32` share 10 
exponent. The only exception to this is `UInt64` and `Int64`.
   2. I'm a little bit lost on mapping for `Float32` and `Float64`. Are 
precision and scale values computed based on 
[`f32::DIGITS`](https://doc.rust-lang.org/std/primitive.f32.html#associatedconstant.DIGITS)
 and 
[`f64::DIGITS`](https://doc.rust-lang.org/std/primitive.f64.html#associatedconstant.DIGITS)?


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