Skip to content

[BUG] Casting rounded float to string returns "0E0" instead of "0.0" #3947

Closed

Description

@penghuo

What is the bug?
Casting rounded float to string returns "0E0" instead of "0.0"

How can one reproduce the bug?

source=test002 
| eval vv=round((cast(1 as double)/100000)*100, 2) 
| eval sv=cast(vv as string) 
| fields sv

sv = "0E0"

What is the expected behavior?

sv = "0.0"

What is your host/environment?

  • OS: [e.g. iOS]
  • Version [e.g. 22]
  • Plugins

Do you have any screenshots?
n/a

Do you have any additional context?
n/a

Activity

  1. added
    bug
    PPL
    on Jul 30, 2025
  2. yuancu commented on Aug 5, 2025

    @yuancu
    Collaborator

    Root cause:

    Calcite's builtin cast operator leverages the following implementation ( from
    https://github.com/apache/calcite/blob/cfaadedd8fd34c480395f9e843a73bf4bb8fe459/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java#L4430)

      /** CAST(DOUBLE AS VARCHAR). */
      public static String toString(double x) {
        if (x == 0) {
          return "0E0";
        }
        return Double.toString(x);
      }

    If the input equals to 0, it returns a hard-coded 0E0.

  3. yuancu commented on Aug 6, 2025

    @yuancu
    Collaborator

    Btw, I found that casting decimal to string also has special rules in Calcite:

    ... | eval s1 = cast(0.0 as string), s2 = cast(0.99 as string)
    
    s1 = ".0"
    s2 = ".99"
    

    This may not be a bug, but it does cause disparity with the behavior of v2.

  4. LantaoJin commented on Aug 7, 2025

    @LantaoJin
    Member

    Em, I think we should fix them both. ".99" is a not making sense. If we fix "0E0" to "0.0", no reason to keep the ".0". @yuancu

  5. moved this from Not Started to Done in PPL Trackeron Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions