Abdullahsab3 commented on issue #12190:
URL: https://github.com/apache/datafusion/issues/12190#issuecomment-2320208595
Just an educated guess, but could it be that the arithmetic operators are
not passed correctly from the parsed AST, or that the AST is not constructed
correctly? Not entirely sure, but it seems that the first arithmetic operator
is always the one that is applied on the entire expression. For example:
```
> select interval '2 day' - interval '1 day' + interval '1 day';
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 2,
nanoseconds: 0 }") - IntervalMonthDayNano("IntervalMonthDayNano { months: 0,
days: 1, nanoseconds: 0 }") + IntervalMonthDayNano("IntervalMonthDayNano {
months: 0, days: 1, nanoseconds: 0 }") |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 0 years 0 mons 0 days 0 hours 0 mins 0.000000000 secs
|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```
Minus is applied on all of them. I think this is the result of `select
interval '2 day' - interval '1 day' - interval '1 day';`.
Another example:
```
> select interval '2 day' - interval '1 day' + interval '1 day' + interval
'5 day' - interval '3 day';
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 2,
nanoseconds: 0 }") - IntervalMonthDayNano("IntervalMonthDayNano { months: 0,
days: 1, nanoseconds: 0 }") + IntervalMonthDayNano("IntervalMonthDayNano {
months: 0, days: 1, nanoseconds: 0 }") +
IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5, nanoseconds: 0
}") - IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 3,
nanoseconds: 0 }") |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 0 years 0 mons -2 days 0 hours 0 mins 0.000000000 secs
|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row(s) fetched.
Elapsed 0.002 seconds.
```
which seems to be of similar behavior. The minus is applied on all of them,
even transforming the latest minus into a plus. I think that's the result of
`select interval '2 day' - interval '1 day' - interval '1 day' - interval '5
day' + interval '3 day';`
Another weird example with a plus:
```
> select interval '5 day' + interval '1 day' - interval '2 day' - interval
'4 day';
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5,
nanoseconds: 0 }") + IntervalMonthDayNano("IntervalMonthDayNano { months: 0,
days: 1, nanoseconds: 0 }") - IntervalMonthDayNano("IntervalMonthDayNano {
months: 0, days: 2, nanoseconds: 0 }") -
IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 4, nanoseconds: 0
}") |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 0 years 0 mons 8 days 0 hours 0 mins 0.000000000 secs
|
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row(s) fetched.
Elapsed 0.001 seconds.
```
The results seem to correspond with `select interval '5 day' + interval '1
day' - interval '2 day' + interval '4 day';`
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]