You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "LantaoJin (via GitHub)" <gi...@apache.org> on 2026/10/16 06:36:24 UTC

[PR] [CALCITE-7862] ARG_MIN and ARG_MAX should support ARRAY, MAP and ROW keys [calcite]

LantaoJin opened a new pull request, #5333:
URL: https://github.com/apache/calcite/pull/5333

   ## Jira Link
   
   [CALCITE-7862](https://issues.apache.org/jira/browse/CALCITE-7862)
   
   ## Changes Proposed
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
   If possible, please consider writing useful notes for better and faster reviews in your PR.
   -->
   
   `ARG_MIN(value, key)` and `ARG_MAX(value, key)`, and their aliases `MIN_BY` and `MAX_BY`, pass validation when the key is an `ARRAY`, `MAP` or `ROW`, but the Enumerable convention cannot implement them. `MIN`, `MAX` and `ORDER BY` on the same values work.
   
   ```sql
   select arg_min(x, v)
   from (values (1, array[3, 1]), (2, array[1, 5]), (3, array[1, 4])) as t(x, v);
   ```
   
   On `main` this fails with `Unable to implement EnumerableAggregate(group=[{}], A=[ARG_MIN($0, $1)])`, caused by `NoSuchMethodException: SqlFunctions.ltNullable(java.util.List,java.util.List)`. With this change it returns 3.
   
   Cause: `ArgMinMaxImplementor` compares a non-primitive key with `SqlFunctions.ltNullable` / `gtNullable`, which are only declared for `T extends Comparable<T>`. `ARRAY`, `MAP` and `ROW` values are `List`, `Map` and `Object[]` at run time, so code generation finds no method. CALCITE-4813 added overloads of `lesser` / `greater` for these types, which `MIN` / `MAX` use, but not of `ltNullable` / `gtNullable`.
   
   Changes:
   
   - `SqlFunctions` gets `List`, `Map` and `Object[]` overloads of `ltNullable` and `gtNullable`, which delegate to the existing `lt` / `gt` overloads for those types, so keys compare the same way as in `MIN`, `MAX` and `ORDER BY`.
   - `agg.iq` covers `ARG_MIN` / `ARG_MAX` with `ARRAY` (including a `NULL` key, which is skipped), `MAP` and `ROW` keys, next to `MIN` / `MAX` on the same column. `SqlOperatorTest.testArgMin` covers an `ARRAY` key for `ARG_MIN`, `ARG_MAX`, `MIN_BY` and `MAX_BY`.


-- 
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: commits-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7862] ARG_MIN and ARG_MAX should support ARRAY, MAP and ROW keys [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5333:
URL: https://github.com/apache/calcite/pull/5333#issuecomment-6209965001

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5333) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5333&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5333&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=5333&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [84.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5333&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5333&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5333)
   
   


-- 
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: commits-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7862] ARG_MIN and ARG_MAX should support ARRAY, MAP and ROW keys [calcite]

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


-- 
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: commits-unsubscribe@calcite.apache.org

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