-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add support for subtracting timestamps --> intervals #194
Comments
I am going to give this a shot (as we currently have to do some heinous workarounds to calculate intervals from timestamps in IOx) |
Here is a simpler reproducer:
And then
|
I have been thinking about this and did some digging in the code. There are probably two major strategies:
Long term I think approach 1 is likely both the "cleanest" and fastest performance approach, but it will take non trivial time. I may try to bound the time required by just implementing subtraction (end to end in arrow + datafusion), and filing tickets to fill out the rest of the operations (the most useful ones are described in the postgres docs) |
BTW there is a (fairly nasty) workaround to cast to an integer and do the math that way So for example, rather than select now() - interval '10 minutes' You can write something like select CAST(now() as bigint) - 10*60*(1000000000) Which is definitely not very pretty 😢 but it does work |
BTW @bjchambers is working on apache/arrow-rs#527 to add kernels to arrow-rs that would then be usable by DataFusion |
Note: migrated from original JIRA: https://issues.apache.org/jira/browse/ARROW-12234
Usecase
I have two columns, time_of_last_write, and time_of_first_write, and that have type
Timestamp(Nanosecond, None)
and I want to compare them to see how much time has elapsedActual Behavior
When I try to subtract them I get an error that there isn't a common type to coerce the types to:
Expected behavior
The query works (the resulting column should be a duration)
The data looks like this:
Workaround
You can cast the columns to
Int64
/bigint
and then subtract them. Something like:The text was updated successfully, but these errors were encountered: