Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-572407: Floating point values are truncated #898

Closed
slawo-ch opened this issue Apr 8, 2022 · 8 comments
Closed

SNOW-572407: Floating point values are truncated #898

slawo-ch opened this issue Apr 8, 2022 · 8 comments
Assignees
Labels

Comments

@slawo-ch
Copy link

slawo-ch commented Apr 8, 2022

When reading a double value from the server, it is always truncated to 8 digits. Full range of 16 digits should be preserved.

Test here: https://github.com/slawo-ch/SnowflakeBugs/blob/main/src/test/java/FloatsTest.java

Possibly related to ALTER SESSION SET JDBC_QUERY_RESULT_FORMAT='JSON'; which is a required setting unless you want to run insecure VMs.

See: #533

@github-actions github-actions bot changed the title Floating point values are truncated SNOW-572407: Floating point values are truncated Apr 8, 2022
@wheezil
Copy link

wheezil commented Feb 7, 2023

+1 seems like a pretty basic flaw.

@sfc-gh-skumbham
Copy link
Contributor

Thank you for reporting this issue. It appears that the problem is a known issue with JSON formatting. The solution is to switch to the arrow format, which will resolve the problem. We have reported this to the backend team, and once they have addressed the issue, the JDBC driver should be able to handle precision loss without any changes. In the meantime, you can try using the to_decimal/to_number functions to retain precision.

@slawo-ch
Copy link
Author

slawo-ch commented Apr 6, 2023

This is playing catch 22 with the JDBC driver

  • 10 the solution to not having to open up the internals of the JVM is to switch to JSON
  • 20 the solution to having correct data from the driver is to switch to arrow
  • GOTO 10

@sfc-gh-wfateem
Copy link
Collaborator

@slawo-ch The solution to (10) is not necessarily switching to JSON. You just need to add the JVM arguments discussed in #533 and #589 to have the JVM allow deep reflection, which was what was already happening pre-JDK 16.

@jdimeo
Copy link

jdimeo commented Nov 3, 2023

So to get lossless double handling we must use Arrow, but to handle JDK 17 we must use JSON... this is quite a problem

@wheezil
Copy link

wheezil commented Nov 4, 2023

The to_decimal/to_number workaround is not applicable to general double-precision values, because the range of exponents cannot be expressed as a fixed-point result.

Is there any other workaround? Can double-precision values be cast to text and preserve the full precision and range, e.g. 1.23456789012345E+123. There is a lot of flexibility documented at https://docs.snowflake.com/en/sql-reference/sql-format-models, but I'm looking for an example of "this format always works".

I'm guessing that to_char(VALUE, '9d99999999999999EEEE') is close. It is not clearly defined how to pick the correct exponent format, from the doc:

The EE element automatically picks the right number of digits in the exponent, and does not print the + sign, while EEE, EEEE, and EEEEE always print the + or - sign for the exponent and the requested number of digits (leading zeros are not suppressed).

OK, EE chooses the right # of digits, but omits the + sign; does it print the - sign if needed? EEEE has leading zeros in the exponent are a little weird but Java Double.parseDouble() accepts it, so I'm thinking this is maybe the answer?

@mmendonca2
Copy link

Curious to know why this issue was closed. Was the underlying bug fixed?

@wheezil
Copy link

wheezil commented Nov 16, 2023

Closed as "that sounds hard" ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants