You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/08/15 21:06:58 UTC

[GitHub] [arrow-datafusion] alamb opened a new issue, #3166: Support `SUM` or `AVG` on `Time` columns.

alamb opened a new issue, #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166

   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   
   DataFusion does not support `SUM` or `AVG` 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:
   
   ```sql
   select 
     sum(t), 
     avg(t)
   from 
     (select cast ('11:00:00' as TIME) as t) as sq;
   ```
   
   Doing so today will result in
   
   ```sql
   ❯ select 
     sum(t), 
     avg(t)
   from 
     (select cast ('11:00:00' as TIME) 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.
   
   **Describe alternatives you've considered**
   N/A 
   
   **Additional context**
   As described in https://github.com/apache/arrow-datafusion/issues/200 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` or `AVG` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215812764

   @alamb postgrseql cast time to interval and then do SUM and AVG


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1217153317

   Thanks @waitingkuo  -- I am starting to work through my review backlog and will catch up with this shortly


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` or `AVG` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215813515

   @waitingkuo notes that postgres does:
   
   ```bash
   willy=# select pg_typeof(SUM(time '00:00:00')),  pg_typeof(AVg(time '00:00:00'));
    pg_typeof | pg_typeof 
   -----------+-----------
    interval  | interval
   (1 row)
   ```
   
   this make sense otherwise SUM(Time) is just quite strange


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` or `AVG` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215829454

   @alamb i think we could add more expressions like `MAX` and `MIN` here (which is already implemented for timestamp


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215866825

   @alamb should we use [IntervalMonthDayNano](https://github.com/apache/arrow-datafusion/blob/master/datafusion/common/src/scalar.rs#L104) insead?  
   
   this is what we have for now
   ```
       /// 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>),
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1216472454

   @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
   
   ```bash
   ❯ select min(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.
   ❯ 
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1216955085

   @alamb i was wrong, current interval implementation outputs different data type according to different input #3180 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1217153558

   cc @ovr 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb closed issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb closed issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns. 
URL: https://github.com/apache/arrow-datafusion/issues/3166


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215875582

    > do we have interval for now?
   
   🤔  looks like another feature gap https://github.com/apache/arrow-datafusion/pull/3167#discussion_r946145318


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` or `AVG` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215814825

   `java.lang.ConcurrentModificationException` 😆  (our updates got crossed)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215881122

   > 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)` 👍
   > 
   > ```shell
   > ❯ select arrow_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.
   > ```
   
   what about `select interval '1 second'`, should we output `Interval(MonthDayNano)` for making them all consistent?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215874142

   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)` 👍 
   
   ```shell
   ❯ select arrow_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.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] waitingkuo commented on issue #3166: Support `SUM` `AVG`, `MIN`, `MAX` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215832724

   do we have interval for now?
   ```bash
   select '00:00:00'::interval;
   NotImplemented("Unsupported SQL type Interval")
   ```
   
   but this works
   ```bash
   ❯ select interval '1 second';
   +------------------------------------------------+
   | IntervalDayTime("1000")                        |
   +------------------------------------------------+
   | 0 years 0 mons 0 days 0 hours 0 mins 1.00 secs |
   +------------------------------------------------+
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #3166: Support `SUM` or `AVG` on `Time` columns.

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #3166:
URL: https://github.com/apache/arrow-datafusion/issues/3166#issuecomment-1215811470

   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. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org