Skip to content

Conversation

@slfan1989
Copy link
Contributor

@slfan1989 slfan1989 commented Dec 8, 2025

Which issue does this PR close?

Closes #1502.

Rationale for this change

To achieve full compatibility with Spark’s numeric functions, we should implement bround() with the following characteristics:

Expected behavior

Function name: bround(expr, scale)
Rounding mode: HALF_EVEN (bankers’ rounding)
Example:

  • bround(2.5) → 2.0
  • bround(3.5) → 4.0
  • bround(-2.5) → -2.0

Supports: FLOAT, DOUBLE, DECIMAL, INT16/32/64

  • Handles negative scales: e.g., bround(123.4, -1) = 120
  • Null-safe: should return NULL if input is NULL
  • Array and scalar inputs: consistent with current round() implementation

What changes are included in this PR?

This PR adds full support for the bround() function, which performs bankers’ rounding (HALF_EVEN).
The following changes are included:

  • Added native implementation of spark_bround() in the expression layer.
  • Added BRound expression support in NativeConverters for proper Spark → native translation.
  • Added comprehensive unit tests to verify correctness for:
    • Positive and negative numbers
    • Different scale values (including negative scales)
    • Various numeric types (FLOAT, DOUBLE, DECIMAL, INT, LONG)
    • Null input handling

Are there any user-facing changes?

No.

How was this patch tested?

CI.

Signed-off-by: slfan1989 <slfan1989@apache.org>
@slfan1989 slfan1989 marked this pull request as ready for review December 13, 2025 11:20
@slfan1989
Copy link
Contributor Author

@richox Could you please help review this PR? Thank you very much!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement native function of bround

1 participant