Skip to content

Avoid duplicate CheckOverflow evaluation for decimal division #5190

Description

@peterxcli

What is the problem the feature request solves?

Decimal Divide is currently serialized with two consecutive, equivalent CheckOverflow expressions.

After #5171:

The resulting shape is:

CheckOverflow(type=T, fail=F)
  CheckOverflow(type=T, fail=F)
    Divide(...)

The native planner only removes a CheckOverflow whose child is a matching WideDecimalBinaryExpr, or fuses one whose child is a decimal Cast; it does not collapse nested CheckOverflow expressions (planner.rs).

On successful array-valued decimal-division batches, both wrappers therefore perform the precision scan in CheckOverflow.evaluate.

Describe the potential solution

Stop DecimalPrecision.promote from wrapping decimal Divide, while retaining the specialized wrapper in CometDivide.convert. That wrapper is required to handle Comet's native decimal-division overflow sentinel correctly.

Acceptance criteria:

  • Decimal Divide serializes to exactly one CheckOverflow.
  • Its datatype equals Divide.dataType.
  • failOnError is true only for ANSI mode.
  • LEGACY and TRY overflow behavior remains null-producing.
  • ANSI overflow behavior remains error-producing.
  • Existing divide-by-zero behavior is unchanged.
  • Add a proto-level regression covering LEGACY, TRY, and ANSI modes.

Additional context

Raised in review of #5171, while fixing #5075.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions