Skip to content

[common] Fix FLOAT precision checking. (#4656)#4658

Closed
hunshenshi wants to merge 1 commit into
apache:masterfrom
hunshenshi:issue-#4656
Closed

[common] Fix FLOAT precision checking. (#4656)#4658
hunshenshi wants to merge 1 commit into
apache:masterfrom
hunshenshi:issue-#4656

Conversation

@hunshenshi
Copy link
Copy Markdown

Purpose

Linked issue: close #4656

Tests

API and Format

Documentation

throw new NumberFormatException(
s + " cannot be cast to float due to precision loss");
} else {
// Validate precision by comparing the rounded value
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float f = Float.parseFloat(s);

s + " cannot be cast to float due to precision loss");
} else {
// Validate precision by comparing the rounded value
if ((double) f == d || Math.abs(f - d) < Math.abs(d * 1e-6)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use "d * 1e-6"?
what about Double#compare?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The value 1e-6 (which is 0.000001) is typically a reasonable threshold for floating-point comparisons, it's a balance between precision and practical usability.
  2. This approach helps avoid rejecting values that are within the acceptable precision for FLOAT types in databases like MySQL, while still accounting for the limitations of floating-point precision.

} else {
// Significant precision loss detected
throw new NumberFormatException(
s + " cannot be cast to FLOAT due to precision loss");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception message need improve. It needs to cover the comparative failure situation.

@github-actions
Copy link
Copy Markdown

This pull request has had no activity for 90 days and is being marked stale. If you'd like to keep it open, please leave a comment or push a new commit. Thank you for your contribution to Apache Paimon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Precision Loss in castFromStringInternal for Valid Float Values (e.g., -0.0009163)

3 participants