Skip to content

fix: round_even for floats for the single argument case#22344

Open
tarekakrout2021 wants to merge 1 commit into
apache:mainfrom
tarekakrout2021:fix/round-float8-banker-rounding
Open

fix: round_even for floats for the single argument case#22344
tarekakrout2021 wants to merge 1 commit into
apache:mainfrom
tarekakrout2021:fix/round-float8-banker-rounding

Conversation

@tarekakrout2021
Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

round(float8) should match PostgreSQL half-tie behavior (banker's rounding / round-half-to-even).

What changes are included in this PR?

  • Changed round_float() to use round-half-to-even (ties-to-even) for the
    zero-decimal / single-argument case only
  • The two-argument form is intentionally unchanged, as PostgreSQL does not
    support round(double precision, int) — that form operates on numeric types
  • Added regression tests for f32 and f64 with canonical half-tie values
    (2.5, 3.5, -2.5, -3.5)
  • Updated scalar.slt expected output to reflect the corrected behavior

Are these changes tested?

Ran:
cargo test --package datafusion-functions round
and

cargo test -p datafusion --test parquet_integration
cargo test --profile=ci --test sqllogictests

Are there any user-facing changes?

Yes — round(x) where x is a float and x is a half-tie value (e.g. 0.5, 1.5, 2.5)
will now return a different result. This is a correctness fix to match PostgreSQL behavior.

To run the CI : @kumarUjjawal

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 18, 2026
@tarekakrout2021 tarekakrout2021 force-pushed the fix/round-float8-banker-rounding branch from 0a5bc20 to 18a70a7 Compare May 18, 2026 20:38
@kumarUjjawal
Copy link
Copy Markdown
Contributor

Thank you @tarekakrout2021 for working on this, I think we are having a discussion about whether we should opt for PG compatibility just to follow one engine over another, since DuckDb already has the same behavior as Datafusion and it's not the case of one is wrong and the other is right. I think we should keep current behavior unless there is a strong reason to change it.

Let's keep the PR open for more discussion.

@tarekakrout2021
Copy link
Copy Markdown
Author

That makes sense, thanks for taking the time to review this @kumarUjjawal .

If the direction shifts toward exposing a separate round_even function (similar to DuckDB), I’d be happy to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL compatibility: round(float8) should match PostgreSQL half-tie behavior

2 participants