Skip to content

round() mishandles large Int64 and UInt64 values #22696

@pchintar

Description

@pchintar

Describe the bug

round() currently exhibits incorrect behavior for large integer inputs.

For Int64 values greater than 2^53 (9007199254740992), which is the largest integer exactly representable in Float64, round() loses precision and return a different value than the input even though rounding an integer with a non-negative scale should be a no-op. This is partially inspired from #22567 by @neilconway

Example:

SELECT round(arrow_cast(9007199254740993, 'Int64'));

Current output:

9007199254740992.0

Expected output:

9007199254740993

The returned value differs from the input even though no rounding is required.

The same issue can be observed with the two-argument form:

SELECT round(arrow_cast(9007199254740993, 'Int64'), 2);

Current output:

9007199254740992.0

Expected output:

9007199254740993

Related behavior with large UInt64 values

For UInt64 values that exceed i64::MAX, round() fails even when the operation is effectively a no-op.

Example:

SELECT round(arrow_cast(18446744073709551615, 'UInt64'));

Current output:

DataFusion error: Execution error:
round: UInt64 value 18446744073709551615 exceeds i64::MAX and cannot be rounded

Expected output:

18446744073709551615

Similarly:

SELECT round(arrow_cast(18446744073709551615, 'UInt64'), 2);

Current output:

DataFusion error: Execution error:
round: UInt64 value 18446744073709551615 exceeds i64::MAX and cannot be rounded

Expected output:

18446744073709551615

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions