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
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
DataFusion does not support SUM, AVG, MIN or MAX on Time type columns a standard SQL feature that could be used to sum how much cumulative time was spent doing some operation, for example
Reproducer is as follows:
selectsum(t),
avg(t)
from
(select cast ('11:00:00'asTIME) as t) as sq;
Doing so today will result in
❯ selectsum(t),
avg(t)
from
(select cast ('11:00:00'asTIME) as t) as sq;
Plan("The function Sum does not support inputs of type Time64(Nanosecond).")
❯
Describe the solution you'd like
A clear and concise description of what you want to happen.
/// Number of elapsed whole months
IntervalYearMonth(Option<i32>),
/// Number of elapsed days and milliseconds (no leap seconds)
/// stored as 2 contiguous 32-bit signed integers
IntervalDayTime(Option<i64>),
/// A triple of the number of elapsed months, days, and nanoseconds.
/// Months and days are encoded as 32-bit signed integers.
/// Nanoseconds is encoded as a 64-bit signed integer (no leap seconds).
IntervalMonthDayNano(Option<i128>),
Since we are treating Time literals as Nanosecond precision, I agree @waitingkuo that the output of SUM() and AVG() of TIME should be Interval(MonthDayNano) 👍
❯ selectarrow_typeof(cast('10:00:00' as time));
+-----------------------------------------------------------+
| arrowtypeof(CAST(Utf8("10:00:00") AS Time64(Nanosecond))) |
+-----------------------------------------------------------+
| Time64(Nanosecond) |
+-----------------------------------------------------------+
1 row in set. Query took 0.038 seconds.
Since we are treating Time literals as Nanosecond precision, I agree @waitingkuo that the output of SUM() and AVG() of TIME should be Interval(MonthDayNano) 👍
❯ selectarrow_typeof(cast('10:00:00' as time));
+-----------------------------------------------------------+
| arrowtypeof(CAST(Utf8("10:00:00") AS Time64(Nanosecond))) |
+-----------------------------------------------------------+
| Time64(Nanosecond) |
+-----------------------------------------------------------+
1 row in set. Query took 0.038 seconds.
@alamb
what about select interval '1 second', should we output Interval(MonthDayNano) for making them all consistent?
@alamb i've created a pull request for max and min #3178
sum and avg requires more work depends on some change for interval, i'll create another issue to discuss it. once we finished, i'll get back to this issue
❯ selectmin(t), max(t) from (select '00:00:00' as t union select'00:00:01' union select'00:00:02');
+----------+----------+
| MIN(t) | MAX(t) |
+----------+----------+
| 00:00:00 | 00:00:02 |
+----------+----------+
1 row in set. Query took 0.009 seconds.
❯
Activity
alamb commentedon Aug 15, 2022
I also think this is a relatively good first issue as it requires following the model for existing aggregates (e.g. SUM(int64)) so marking it as such.
waitingkuo commentedon Aug 15, 2022
@alamb postgrseql cast
timetointervaland then doSUMandAVGalamb commentedon Aug 15, 2022
@waitingkuo notes that postgres does:
this make sense otherwise SUM(Time) is just quite strange
alamb commentedon Aug 15, 2022
java.lang.ConcurrentModificationException😆 (our updates got crossed)waitingkuo commentedon Aug 15, 2022
@alamb i think we could add more expressions like
MAXandMINhere (which is already implemented for timestamp[-]Support `SUM` or `AVG` on `Time` columns. [/-][+]Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns. [/+]waitingkuo commentedon Aug 15, 2022
do we have interval for now?
but this works
waitingkuo commentedon Aug 15, 2022
@alamb should we use IntervalMonthDayNano insead?
this is what we have for now
alamb commentedon Aug 15, 2022
Since we are treating
Timeliterals asNanosecondprecision, I agree @waitingkuo that the output ofSUM()andAVG()ofTIMEshould beInterval(MonthDayNano)👍alamb commentedon Aug 15, 2022
🤔 looks like another feature gap #3167 (comment)
waitingkuo commentedon Aug 15, 2022
@alamb
what about
select interval '1 second', should we outputInterval(MonthDayNano)for making them all consistent?waitingkuo commentedon Aug 16, 2022
@alamb i've created a pull request for max and min #3178
sumandavgrequires more work depends on some change for interval, i'll create another issue to discuss it. once we finished, i'll get back to this issuewaitingkuo commentedon Aug 16, 2022
@alamb i was wrong, current interval implementation outputs different data type according to different input #3180
alamb commentedon Aug 16, 2022
Thanks @waitingkuo -- I am starting to work through my review backlog and will catch up with this shortly
alamb commentedon Aug 16, 2022
cc @ovr