kazuyukitanimura commented on PR #1416:
URL: 
https://github.com/apache/datafusion-comet/pull/1416#issuecomment-2667956389

   > > wondering if we can fix in arrow/datafusion
   > > It looks addition is working, I wonder what would be the difference 
between `+` and `%`
   > 
   > It seems to be by design in rust: 
https://github.com/rust-lang/rust/blob/f44efbf9e11b1b6bba77c046d7dd150de37e0e0f/library/core/src/num/int_macros.rs#L993
   
   Thanks for digging into the rust source.
   Perhaps I am missing something but still not clear to me...
   rust `-2147483648 + -1` overflows
   ```
   >> let r = -2147483648 + -1;
   [arithmetic_overflow] Error: this arithmetic operation will overflow
      ╭─[command:1:1]
      │
    1 │ let r = -2147483648 + -1;
      │         ────────┬───────  
      │                 ╰───────── attempt to compute `i32::MIN + -1_i32`, 
which would overflow
   ───╯
   ```
   But DataFusion is allowing the overflow
   ```
   $datafusion-cli                                             
   DataFusion CLI v44.0.0
   > create table t1(c1 int, c2 int);
   0 row(s) fetched. 
   Elapsed 0.016 seconds.
   
   > insert into t1 values(-2147483648, -1);
   +-------+
   | count |
   +-------+
   | 1     |
   +-------+
   1 row(s) fetched. 
   Elapsed 0.027 seconds.
   
   > select c1 + c2 from t1;
   +---------------+
   | t1.c1 + t1.c2 |
   +---------------+
   | 2147483647    |
   +---------------+
   1 row(s) fetched. 
   Elapsed 0.010 seconds.
   
   > select c1 % c2 from t1;
   Arrow error: Arithmetic overflow: Overflow happened on: -2147483648 % -1
   ```
   
   It looks postgres also returns 0, I will open a datafusion ticket on this


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to