datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

round() mishandles large Int64 and UInt64 values

Open pchintar opened this issue 6 months ago • 0 comments

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

pchintar avatar Jun 01 '26 11:06 pchintar