Skip to content

Casting Decimal128 to Decimal128 with smaller precision produces incorrect results in some cases #6833

@andygrove

Description

@andygrove

Describe the bug

If I try and cast floating-point value 12345.67 to decimal(6,2) then I get an error, as expected:

"1234567 is too large to store in a Decimal128 of precision 6. Max is 999999"

However, if I try and cast a decimal(24,2) value of 12345.67 to decimal(6,2) then I do not get an error but instead have an invalid decimal value.

PrimitiveArray<Decimal128(6, 2)>
[
    1234567,
]

If I then convert this decimal to a string, it produces 1234.56 instead of 12345.67

StringArray
[
  "1234.56",
]

To Reproduce

Expected behavior

Additional context

This is the root cause of apache/datafusion#13492

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrowChanges to the arrow cratebug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions