You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
is there a way to get a result similar to datediff function #7097
Is your feature request related to a problem or challenge?
I’d like to ask if there is a way to get a result similar to datediff function , also it seems that this function is not available in DataFusion.
i try another way like this,but how can i get 6 days from interval result
select to_timestamp(now())-to_timestamp('2023-07-20T05:44:00.419557');
+------------------------------------------------------------------------+
| to_timestamp(now()) - to_timestamp(Utf8("2023-07-20T05:44:00.419557")) |
+------------------------------------------------------------------------+
| 0 years 0 mons 6 days 0 hours 51 mins 7.343851000 secs |
+------------------------------------------------------------------------+
Describe the solution you'd like
something like date_diff
Describe alternatives you've considered
add udf like date_diff
or
make select extract(day from interval '1 days' );
work
Error during planning: No function matches the given name and argument types 'date_part(Utf8, Interval(MonthDayNano))'. You might need to add explicit type casts.
Candidate functions:
date_part(Utf8, Date32)
date_part(Utf8, Date64)
date_part(Utf8, Timestamp(Second, None))
date_part(Utf8, Timestamp(Microsecond, None))
date_part(Utf8, Timestamp(Millisecond, None))
date_part(Utf8, Timestamp(Nanosecond, None))
date_part(Utf8, Timestamp(Nanosecond, Some("+00:00")))
Adding them seems like a good idea to me. However, st some point we probably need to figure out how to split functions into packages so users can mix/match "packages" of functions they want without having to get all of the others. I filed #7110 to track this idea
What would extract (.. from interval ..) do? Perhaps you could provide an example or a link to another database system that implements such a function?
Activity
alamb commentedon Jul 26, 2023
I agree that adding support for for intervals to
EXTRACTwould be very helpful.alamb commentedon Jul 26, 2023
I think this would be a good first issue as the wiring is all done and this would be a relatively simple extension to date_part I think
alamb commentedon Jul 26, 2023
For example, either use or follow https://docs.rs/arrow/latest/arrow/compute/fn.day.html
smallzhongfeng commentedon Jul 27, 2023
Do we have plans to support date_diff, date_add and other time functions, @alamb such as comparing spark's udf function about
date? https://spark.apache.org/docs/3.4.1/api/sql/search.html?q=datealamb commentedon Jul 27, 2023
There do not appear to be any such plans: https://github.com/apache/arrow-datafusion/issues?q=is%3Aissue+is%3Aopen+date_diff+
Adding them seems like a good idea to me. However, st some point we probably need to figure out how to split functions into packages so users can mix/match "packages" of functions they want without having to get all of the others. I filed #7110 to track this idea
🤔
NiwakaDev commentedon Jul 30, 2023
@alamb
I'd like to implement the following feature:
alamb commentedon Jul 31, 2023
Thanks @NiwakaDev -- let us know if you run into any trouble.
NiwakaDev commentedon Oct 21, 2023
As far as I understand, it seems like this issue depends on apache/arrow-rs#4969.
alamb commentedon Oct 23, 2023
@NiwakaDev I am not sure about this.
Note DataFusion already supports
extractfor several field types:https://arrow.apache.org/datafusion/user-guide/sql/scalar_functions.html#extract
What would
extract (.. from interval ..)do? Perhaps you could provide an example or a link to another database system that implements such a function?Jefffrey commentedon Dec 31, 2023
Note there is an existing issue for implementing
extract(X from interval)in Datafusion here: #6327I've also put details in a comment there with comparison of other engines behaviour