izveigor opened a new issue, #6649:
URL: https://github.com/apache/arrow-datafusion/issues/6649

   ### Describe the bug
   
   There are several cases, when parser does not work correctly. I can draw 
this conclusion from the comparison PostgreSQL and Arrow Datafusion queries.
   Main causes of errors:
   1) The precedence of bitwise shifts does not equal to other bitwise 
operators.
   2) Unary operation `-` with the operations `*`, `/` and `%`  negates the 
result of the next statements.
   3) The same problem like `(2)` we have with `Intervals`, when we want to add 
or subtract negative interval with other, we negate the whole result except of 
one interval.
   
   ### To Reproduce
   
   | SQL expression | Arrow Datafusion | PostgreSQL |
   | ----------------- | ------------------- | -------------|
   | `select 15 \| 12331233 >> 1234123 & 12;` | 4 | 48175 |
   | `select - 1234 % 12 % 3 * 1545 % 23;` | -4 | -17 |
   | `select - 1234 % 12 % 3 * 1545 % 23;` | -4 | -22 |
   | `select - 13 * 1324 * -234 / 24 * 23;` | 3562884 | 3859791|
   | `select -12 * 35 % -16 * 32;` | -420 | -128|
   | `select - interval '16 hours' + interval '2 hours';` | 18:00:00 | 
-14:00:00 |
   
   ```
   DataFusion CLI v25.0.0
   ❯ select 15 | 12331233 >> 1234123 & 12;
   +-----------------------------------------------------------+
   | Int64(15) | Int64(12331233) >> Int64(1234123) & Int64(12) |
   +-----------------------------------------------------------+
   | 48175                                                     |
   +-----------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ❯ select - 1234 % 12 % 3 * 1545 % 23;
   +------------------------------------------------------------------+
   | (- Int64(1234) % Int64(12) % Int64(3) * Int64(1545) % Int64(23)) |
   +------------------------------------------------------------------+
   | -4                                                               |
   +------------------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ❯ select - 1234 % 12 % 3 * 1545 % 23;
   +------------------------------------------------------------------+
   | (- Int64(1234) % Int64(12) % Int64(3) * Int64(1545) % Int64(23)) |
   +------------------------------------------------------------------+
   | -4                                                               |
   +------------------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ❯ select - 13 * 1324 * -234 / 24 * 23;
   +----------------------------------------------------------------------+
   | (- Int64(13) * Int64(1324) * (- Int64(234) / Int64(24) * Int64(23))) |
   +----------------------------------------------------------------------+
   | 3562884                                                              |
   +----------------------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ❯ select -12 * 35 % -16 * 32;
   +-------------------------------------------------------+
   | (- Int64(12) * Int64(35) % (- Int64(16) * Int64(32))) |
   +-------------------------------------------------------+
   | -420                                                  |
   +-------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ❯ select - interval '16 hours' + interval '2 hours';
   
+------------------------------------------------------------------------------------+
   | (- IntervalMonthDayNano("57600000000000") + 
IntervalMonthDayNano("7200000000000")) |
   
+------------------------------------------------------------------------------------+
   | 0 years 0 mons 0 days -18 hours 0 mins 0.000000000 secs                    
        |
   
+------------------------------------------------------------------------------------+
   1 row in set. Query took 0.000 seconds.
   ❯ 
   ```
   **BUT:**
   ```
   ❯ select -(interval '2 hours' + interval '3 hours') + (interval '5 hours' - 
interval '2 hours');
   
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | (- IntervalMonthDayNano("7200000000000") + 
IntervalMonthDayNano("10800000000000")) + 
IntervalMonthDayNano("18000000000000") - IntervalMonthDayNano("7200000000000") |
   
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | 0 years 0 mons 0 days -2 hours 0 mins 0.000000000 secs                     
                                                                                
         |
   
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ```
   
   ```
   postgres=# select -(interval '2 hours' + interval '3 hours') + (interval '5 
hours' - interval '2 hours');
    ?column?  
   -----------
    -02:00:00
   (1 row)
   ```
   
   ```
   ❯ select -2 + -2 + 5 + -5;
   +----------------------------------------------+
   | Int64(-2) + Int64(-2) + Int64(5) + Int64(-5) |
   +----------------------------------------------+
   | -4                                           |
   +----------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ```
   
   ```
   postgres=# select -2 + -2 + 5 + -5;
    ?column? 
   ----------
          -4
   (1 row)
   ```
   
   ```
   ❯ select -2 + -2 - 5 + -5;
   +----------------------------------------------+
   | Int64(-2) + Int64(-2) - Int64(5) + Int64(-5) |
   +----------------------------------------------+
   | -14                                          |
   +----------------------------------------------+
   1 row in set. Query took 0.000 seconds.
   ```
   
   ```
   postgres=# select -2 + -2 - 5 + -5;
    ?column? 
   ----------
         -14
   (1 row)
   ```
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to