-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order of Interval Addition Should Affect Final Output #11055
Comments
🤔 maybe we could turn of constant folding for adding intervals |
take |
I agree with @Lordworms the root cause is related to the precidence rules in sqlparser which control if expressions like DATE '2019-02-28' + INTERVAL '1 YEAR' + INTERVAL '1 DAY' AS FEB, are parsed like this ((DATE '2019-02-28' + INTERVAL '1 YEAR') + INTERVAL '1 DAY' AS FEB), Or like (DATE '2019-02-28' + (INTERVAL '1 YEAR' + INTERVAL '1 DAY' AS FEB)), Users who want to control the order of expression evaluation can use |
Thanks so much. Should I fix it in sqlparser? |
I think that is probably the best way -- though it is likely pretty tricky (likely related to operator precidence). I think the correct first step would be to do some research and see how such arithmetic is parsed by other databases |
Describe the bug
In various engines, the order in which intervals are added to dates can affect the final value. This is especially noticeable with leap years.
Datafusion appears to constant fold these intervals, which throws away the operation order.
To Reproduce
Testing via datafusion-cli
Expected behavior
Due to leap year shenanigans, adding the year before the day results in a different date than adding the day before the year.
Trino emits
as does Postgres and Snowflake (based on their documentation for interval types where this example came from)
Additional context
No response
The text was updated successfully, but these errors were encountered: