Skip to content
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

[BUG] Error when adding Date32 and Int64 #12342

Open
comphead opened this issue Sep 5, 2024 · 5 comments · May be fixed by #13741
Open

[BUG] Error when adding Date32 and Int64 #12342

comphead opened this issue Sep 5, 2024 · 5 comments · May be fixed by #13741
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@comphead
Copy link
Contributor

comphead commented Sep 5, 2024

Describe the bug

DataFusion 41

>  select to_date('1970-01-01', 'yyyy-mm-dd') + 5;
Error during planning: Cannot coerce arithmetic expression Date32 + Int64 to valid types

The same query runs ok in Postgres
Workaround

> select to_date('1970-01-01') + interval '5' day;
+-------------------------------------------------------------------------------------------------------------------+
| to_date(Utf8("1970-01-01")) + IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5, nanoseconds: 0 }") |
+-------------------------------------------------------------------------------------------------------------------+
| 1970-01-06                                                                                                        |
+-------------------------------------------------------------------------------------------------------------------+

To Reproduce

 select to_date('1970-01-01', 'yyyy-mm-dd') + 5;

Expected behavior

Query should work

Additional context

No response

@comphead comphead added the bug Something isn't working label Sep 5, 2024
@comphead comphead changed the title [BUG] Cannot add Date32 and Int64 [BUG] Error when adding Date32 and Int64 Sep 5, 2024
@comphead comphead added the good first issue Good for newcomers label Sep 5, 2024
@Omega359
Copy link
Contributor

Omega359 commented Sep 5, 2024

That is an odd thing for pg to support because the unit for the int is implied as it could just as well be months or years.

@comphead
Copy link
Contributor Author

comphead commented Sep 5, 2024

That is an odd thing for pg to support because the unit for the int is implied as it could just as well be months or years.

I cannot find the standard right away, but for binary ops with Date and numeric, the numeric is supposed to be number of days

@gnayus
Copy link

gnayus commented Nov 28, 2024

Using intervals, both of the following work:

select to_date('1970-01-01') + interval '5' day;
select interval '5' day + to_date('1970-01-01');

Do we want to support both cases for Date32 and Int64 as well?

select to_date('1970-01-01', 'yyyy-mm-dd') + 5;
select 5 + to_date('1970-01-01', 'yyyy-mm-dd');

How about minus?

select to_date('1970-01-01', 'yyyy-mm-dd') - 5;

@milevin
Copy link

milevin commented Dec 9, 2024

take

@milevin
Copy link

milevin commented Dec 12, 2024

I put up a PR, but it's not perfect as I describe in its summary. Would love to get feedback and suggestions from the experts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
4 participants