[dbolympics] Support multiply and divide on intervals
Is your feature request related to a problem or challenge?
Copied directly from https://github.com/apache/arrow-rs/issues/6335 from @samuelcolvin
In Postgres I can do:
select 3 * interval '1 day';
select interval '1 day' * 3; -- same
select 1.23 * interval '1 day';
-- and divide
select interval '1 day' / 3;
I started trying to add support for this to datafusion but discovered that the operations aren't supported in arrow-rs and adding them (with support for all numeric types) is far from trivial.
Describe the solution you'd like
The idea is to support the syntax above in DataFusion
High level steps are:
- [ ] Arrow-rs support: https://github.com/apache/arrow-rs/pull/6906
- [ ] PR in DataFusion to allow the operations and add appropriate tests
Describe alternatives you've considered
No response
Additional context
I believe @milevin is already working on this (so perhaps you would like to assign this ticket to yourself via take)
take
take
With this, datafusion-comet could have native support for multiply_ym_interval, multiply_dt_interval and divide_dt_interval, instead of using the codegen dispatch path.
https://github.com/apache/arrow-rs/issues/6335 is implemented. I will try to integrate it into df whenever the next arrow-rs release is out.
@peterxcli are you still working on this? The arrow-rs side (apache/arrow-rs#6335) is in the arrow 60 that DataFusion now depends on, so the remaining part is on the DataFusion side: temporal_math_coercion currently coerces the number to Interval(MonthDayNano), which arrow rejects as Interval * Interval. If you have not started, I am happy to take it over and send a PR that keeps the numeric operand as Int64/Float64 and adds sqllogictests for * and /.
@peterxcli since the arrow side has been released for a while and I did not hear back, I went ahead and opened #26258 with the DataFusion side (coercion to Int64/Float64 instead of Interval, checked mul kernel, sqllogictests for * and / with integers, floats, NULLs and columns). If you already have work in progress I am happy to close mine or rebase on yours.
Affects DB Olympics, see: https://github.com/apache/datafusion/issues/26661
#26258 implements this (interval * number, number * interval, interval / number, with sqllogictests). It has no conflicts with main and is ready for review whenever someone has time.