You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "svranesevic (via GitHub)" <gi...@apache.org> on 2025/03/19 13:34:34 UTC

[PR] Support Duration in min/max agg functions [datafusion]

svranesevic opened a new pull request, #15310:
URL: https://github.com/apache/datafusion/pull/15310

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   /
   
   ## Rationale for this change
   
   Support min/max aggregation of expressions with duration type.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   Extend min/max agg functions to support Duration.
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   Yes, extended `aggregate.slt` with test cases.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   Yes, min/max aggregation functions can be used with expressions of duration type.
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support Duration in min/max agg functions [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15310:
URL: https://github.com/apache/datafusion/pull/15310#issuecomment-2739772947

   Thanks again @svranesevic 


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support Duration in min/max agg functions [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15310:
URL: https://github.com/apache/datafusion/pull/15310#issuecomment-2739772489

   <img width="1052" alt="Screenshot 2025-03-20 at 5 47 34 AM" src="https://github.com/user-attachments/assets/c4de068f-d54e-4125-9392-ea77c6cfd308" />
   Will do -- thanks @svranesevic 
   
   I normally try and wait for abour 24 hours before merging non trivial approved PRs to give a chance for other contributors in different timezones to review
   
   In this case, however, I think the PR is small enough and non contrversial that we can merge now


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support Duration in min/max agg functions [datafusion]

Posted by "svranesevic (via GitHub)" <gi...@apache.org>.
svranesevic commented on PR #15310:
URL: https://github.com/apache/datafusion/pull/15310#issuecomment-2739373267

   Thanks @alamb!
   Feel free to merge whenever, it seems that I can not do so even after approval.


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support Duration in min/max agg functions [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #15310:
URL: https://github.com/apache/datafusion/pull/15310


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support Duration in min/max agg functions [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15310:
URL: https://github.com/apache/datafusion/pull/15310#discussion_r2004167614


##########
datafusion/sqllogictest/test_files/aggregate.slt:
##########
@@ -3807,6 +3807,38 @@ SELECT MIN(value), MAX(value) FROM timestampmicrosecond
 statement ok
 DROP TABLE timestampmicrosecond;
 
+# min_duration, max_duration
+statement ok
+create table d
+as values
+  (arrow_cast(1, 'Duration(Second)'), arrow_cast(2, 'Duration(Millisecond)'),  arrow_cast(3, 'Duration(Microsecond)'),  arrow_cast(4, 'Duration(Nanosecond)'), 1),
+  (arrow_cast(11, 'Duration(Second)'),arrow_cast(22, 'Duration(Millisecond)'), arrow_cast(33, 'Duration(Microsecond)'), arrow_cast(44, 'Duration(Nanosecond)'), 1);
+
+query ????
+SELECT min(column1), min(column2), min(column3), min(column4) FROM d;
+----
+0 days 0 hours 0 mins 1 secs 0 days 0 hours 0 mins 0.002 secs 0 days 0 hours 0 mins 0.000003 secs 0 days 0 hours 0 mins 0.000000004 secs
+
+query ????
+SELECT max(column1), max(column2), max(column3), max(column4) FROM d;
+----
+0 days 0 hours 0 mins 11 secs 0 days 0 hours 0 mins 0.022 secs 0 days 0 hours 0 mins 0.000033 secs 0 days 0 hours 0 mins 0.000000044 secs
+
+# GROUP BY follows a different code path

Review Comment:
   I also added some tests when there is GROUP BY in the query as that takes a different code path
   
   I actually double checked and there is a way to make this kind of query faster, which I filed as
   - https://github.com/apache/datafusion/issues/15317



##########
datafusion/sqllogictest/test_files/aggregate.slt:
##########
@@ -3807,6 +3807,26 @@ SELECT MIN(value), MAX(value) FROM timestampmicrosecond
 statement ok
 DROP TABLE timestampmicrosecond;
 
+# min_duration, max_duration
+statement ok
+create table d
+as values
+  (arrow_cast(1, 'Duration(Second)'), arrow_cast(2, 'Duration(Millisecond)'),  arrow_cast(3, 'Duration(Microsecond)'),  arrow_cast(4, 'Duration(Nanosecond)')),
+  (arrow_cast(11, 'Duration(Second)'),arrow_cast(22, 'Duration(Millisecond)'), arrow_cast(33, 'Duration(Microsecond)'), arrow_cast(44, 'Duration(Nanosecond)'));
+
+query ????
+SELECT min(column1), min(column2), min(column3), min(column4) FROM d;

Review Comment:
   I verified these queries fail without this change:
   
   ```sql
   > SELECT min(column1), min(column2), min(column3), min(column4) FROM d;
   Internal error: Min/Max accumulator not implemented for type Duration(Second).
   This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
   >
   ```
   
   



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support Duration in min/max agg functions [datafusion]

Posted by "svranesevic (via GitHub)" <gi...@apache.org>.
svranesevic commented on PR #15310:
URL: https://github.com/apache/datafusion/pull/15310#issuecomment-2740356069

   > I normally try and wait for abour 24 hours before merging non trivial approved PRs to give a chance for other contributors in different timezones to review
   
   Oh, I was not aware of that 👍  Pinged just to avoid dead-lock situation where we wait for the other one to merge 🙂 


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org