You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "danzhewuju (via GitHub)" <gi...@apache.org> on 2025/03/12 06:20:32 UTC

[I] [Bug] Paimon throws an exception "cannot be cast to float due to precision loss" when the float data has five decimal places or more. [paimon]

danzhewuju opened a new issue, #5263:
URL: https://github.com/apache/paimon/issues/5263

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/paimon/issues) and found nothing similar.
   
   
   ### Paimon version
   
   paimon-1.0
   
   ### Compute Engine
   
   Flink 1.17
   
   ### Minimal reproduce step
   
   Insert any floating-point data with five or more decimal places into the Paimon table.
   
   ### What doesn't meet your expectations?
   
   Thers is the code that cast string to float。 In fact, when a number has four decimal places, converting a float type to a String type will result in scientific notation. In this case, directly comparing their string lengths is meaningless. However, when the number has exactly four decimal places, the lengths happen to be the same (e.g. len(0.0001) = len(2.0E-4)). so when there are exactly faive decimal places, which will throw the exception.
   ```
   case FLOAT:
                   double d = Double.parseDouble(s);
                   if (d == ((float) d)) {
                       return (float) d;
                   } else {
                       // Compatible canal-cdc
                       Float f = Float.valueOf(s);
                       if (f.toString().length() != s.length()) {
                           throw new NumberFormatException(
                                   s + " cannot be cast to float due to precision loss");
                       } else {
                           return f;
                       }
                   }
   ```
   
   ![Image](https://github.com/user-attachments/assets/4e9abe1a-00f1-4594-a1c8-9a4806ba9e56)
   
   <img width="812" alt="Image" src="https://github.com/user-attachments/assets/c5283d2d-a847-44c8-8012-1dbec2ba0bd2" />
   
   org.apache.paimon.utils.TypeUtils#castFromStringInternal() 
   
   
   
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
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: issues-unsubscribe@paimon.apache.org.apache.org

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


Re: [I] [Bug] Paimon throws an exception "cannot be cast to float due to precision loss" when the float data has five decimal places or more. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi closed issue #5263: [Bug] Paimon throws an exception "cannot be cast to float due to precision loss" when the float data has five decimal places or more.
URL: https://github.com/apache/paimon/issues/5263


-- 
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: issues-unsubscribe@paimon.apache.org

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