goldmedal commented on issue #10688:
URL: https://github.com/apache/datafusion/issues/10688#issuecomment-2138499681

   After some testing, I found it could be an arrow-cast issue. When trying to 
cast a float32 to float64, the precision is missing.
   We can easy to reproduce this case like:
   ```
   > select (128.2::float)::double
   ;
   +-------------------+
   | Float64(128.2)    |
   +-------------------+
   | 128.1999969482422 |
   +-------------------+
   1 row(s) fetched. 
   Elapsed 0.089 seconds.
   ```
   
   I found it happens in `SimplifyExpressions` rule. `SimpleExpr` will try to 
evaluate the casting expression. 
   
https://github.com/apache/datafusion/blob/3d007608535cb138ae4473ce6305bd4ec8481627/datafusion/common/src/scalar/mod.rs#L2506
   
   `cast_to` will invoke the arrow-cast to get the result.
   It can also be reproduced like
   ```rust
       let expr2 = ScalarValue::Float64(Some(128.2))
       .cast_to(&DataType::Float32)
       .unwrap()
       .cast_to(&DataType::Float64)
       .unwrap();
       println!("expr2: {:?}", expr2);
   ------------------------------------
   expr2: Float64(128.1999969482422)
   ```
   It happens in `arrow-cast-51.0.0/src/cast.rs` (I'm not sure where is the 
code placed).
   ```rust
   (Float16, Float32) => cast_numeric_arrays::<Float16Type, Float32Type>(array, 
cast_options),
   ```
   I think it maybe not a DataFusion issue but a arrow-cast issue.
   
   @comphead @viirya What do you think?


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

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