Skip to content

Implement native function of bround #1502

@slfan1989

Description

@slfan1989

Description

Implement Spark-compatible bround() (bankers’ rounding) function

In PR #1327, we introduced support for the round() function following Spark’s semantics (HALF_UP rounding mode).
However, Spark also provides a companion function bround() that performs bankers’ rounding (HALF_EVEN mode), which rounds ties to the nearest even number.

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

Motivation

  • Ensure feature parity with Apache Spark SQL
  • Improve compatibility for expressions and queries migrated from Spark
  • Reduce fallback occurrences to Spark UDF wrapper

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions