Skip to content

Conversation

@yuancu
Copy link
Collaborator

@yuancu yuancu commented Aug 19, 2025

Description

Backport #3982 to 2.19-dev

Commit Message

  • Fix casting double 0.0 to string

  • Fix float to string casting precision lost with custom FormatNumberFunction

This commit fixes float to string casting by replacing the use of SqlLibraryOperators.FORMAT_NUMBER with a custom FormatNumberFunction implementation. The new implementation converts the number to a BigDecimal before formatting to preserve precision and avoid issues like 6.2 becoming 6.199999809265137.

  • Simplify the implementation of fp number to string cast

  • Update implementation of NumberToStringFunction

  • Cast decimal with NUMBER_TO_STRING function

  • Test cast decimal


(cherry picked from commit 1977083)

Related Issues

Resolves #3947

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

opensearch-project#3982)

* Fix casting double 0.0 to string

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Fix float to string casting precision lost with custom FormatNumberFunction

This commit fixes float to string casting by replacing the use of SqlLibraryOperators.FORMAT_NUMBER
with a custom FormatNumberFunction implementation. The new implementation converts the number
to a BigDecimal before formatting to preserve precision and avoid issues like 6.2 becoming
6.199999809265137.

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Simplify the implementation of fp number to string cast

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Update implementation of NumberToStringFunction

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Cast decimal with NUMBER_TO_STRING function

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

* Test cast decimal

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>

---------

Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
(cherry picked from commit 1977083)
@LantaoJin LantaoJin merged commit ab211df into opensearch-project:2.19-dev Aug 19, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants