Support ANSI mode for `negate` function
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Is your feature request related to a problem or challenge?
https://github.com/apache/datafusion/pull/20006 now supports `negate` function for Spark, however it should also consider ANSI mode
```
///
///
/// Returns the negation of input (equivalent to unary minus)
/// Returns NULL if input is NULL, returns NaN if input is NaN.
///
/// TODOs:
/// - Spark's ANSI-compliant dialect, when off (i.e. `spark.sql.ansi.enabled=false`),
/// negating the minimal value of a signed integer wraps around.
/// For example: negative(i32::MIN) returns i32::MIN (wraps instead of error).
/// This is the current implementation (legacy mode only).
/// - Spark's ANSI mode (when `spark.sql.ansi.enabled=true`) should throw an
/// ARITHMETIC_OVERFLOW error on integer overflow instead of wrapping.
/// This is not yet implemented - all operations currently use wrapping behavior.
```
### Describe the solution you'd like
_No response_
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the negate implementation introduced by pull request 20006 and trace how Spark ANSI mode is represented in DataFusion. Verify that negating the minimum signed integer wraps in legacy mode but reports an ARITHMETIC_OVERFLOW error in ANSI mode, covering the existing negate behavior with tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100