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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to