Skip to content

Parser not working properly #6649

Description

@izveigor

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:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions