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

timestamp - interval results in The type of Timestamp(Nanosecond, Some("+00:00")) Minus Utf8 of binary physical should be same #5650

Closed
Tracked by #3148
alamb opened this issue Mar 20, 2023 · 5 comments · Fixed by #5696
Labels
bug Something isn't working

Comments

@alamb
Copy link
Contributor

alamb commented Mar 20, 2023

Describe the bug
I ran a query and got an internal error

To Reproduce
Using datafusion-cli:

❯ create table foo(x timestamp) as select '2023-03-01'::timestamp;
0 rows in set. Query took 0.002 seconds.
❯ select * from foo;
+---------------------+
| x                   |
+---------------------+
| 2023-03-01T00:00:00 |
+---------------------+
1 row in set. Query took 0.001 seconds.
❯ select * from foo where x < now() - '1 day';
The type of Timestamp(Nanosecond, Some("+00:00")) Minus Utf8 of binary physical should be same. This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker

Note it is possible to use the interval syntax things work out correctly

❯ select * from foo where x < now() - interval '1 day';
+---------------------+
| x                   |
+---------------------+
| 2023-03-01T00:00:00 |
+---------------------+

Note if you try to use the same predicate outside of the where clause, we get a planning error (correctly):

❯ select now()  - '1 day';
Error during planning: 'Timestamp(Nanosecond, Some("+00:00")) - Utf8' can't be evaluated because there isn't a common type to coerce the types to

Expected behavior

  1. (minimum) select * from foo where x < now() - '1 day'; should produce a planning error (rather than an internal error)
  2. (ideal) Make the query work

Additional context

@comphead
Copy link
Contributor

@alamb select * from foo where x < now() - '1 day' such kind of queries doesn't work in PG. I would think it is expected behavior as '1 day' is really string.

@alamb
Copy link
Contributor Author

alamb commented Mar 21, 2023

@alamb select * from foo where x < now() - '1 day' such kind of queries doesn't work in PG. I would think it is expected behavior as '1 day' is really string.

I was imagining that we could coerce Utf8 --> interval automatically -- see #5652

For this ticket, I think we should generate a Plan error rather than an Internal error

@Weijun-H
Copy link
Contributor

@alamb select * from foo where x < now() - '1 day' such kind of queries doesn't work in PG. I would think it is expected behavior as '1 day' is really string.

I was imagining that we could coerce Utf8 --> interval automatically -- see #5652

For this ticket, I think we should generate a Plan error rather than an Internal error

I agree that this is an error in plan. If no one else is working on it, I can take responsibility for resolving it.

@comphead
Copy link
Contributor

@alamb are you also expect the case like that to be valid?

with t as
(
    select '1 day' as intvl
) select now() - t.invl from t

Or it has to be literal to make such kind of cast?

@alamb
Copy link
Contributor Author

alamb commented Mar 23, 2023

@alamb are you also expect the case like that to be valid?

Eventually I would like that case to work. It will require more work (both in arrow to get the appropriate evaluation kernels and datafusion to do the casting / coercion).

I have it on my list to write up the steps for such support (it is a priority for us on IOx now as people start using intervals more widely). I expect a writeup in a day or two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants