LantaoJin commented on PR #5330:
URL: https://github.com/apache/calcite/pull/5330#issuecomment-6188749376

   > I will review this tomorrow.
   
   Thanks. Some context for you on why I filed this PR.
   
   #5331 adds a `VECTOR` type whose comparability is `NONE`, since embeddings 
have no meaningful order. On that branch, without this fix:
   
   ```sql
   SELECT MIN(v) FROM t;          -- validation error: Cannot apply 'MIN' to 
arguments of type 'MIN(<VECTOR(2, REAL)>)'
   SELECT x FROM t ORDER BY v;    -- validation error: Values of type 
'VECTOR(2, REAL)' are not comparable
   SELECT ARG_MIN(x, v) FROM t;   -- validates, then fails with 
IllegalStateException:
                                  --   Unable to implement 
EnumerableAggregate(group=[{}], A=[ARG_MIN($0, $1)])
   ```
   
   So `VECTOR` would be the first built-in type that reports `NONE`, and 
`ARG_MIN` / `ARG_MAX` / `MIN_BY` / `MAX_BY` are the only places where that is 
not enforced; the user gets an internal error instead of a validation error. 
This PR is what makes them consistent. It changes nothing for types that report 
`ALL`, which includes every other built-in type.
   
   > all types are comparable at run time
   
   for these functions that is not quite true on the Enumerable convention 
today. On `main`, `ARG_MIN(x, v)` with `v` an `ARRAY` (comparability `ALL`) 
validates and then fails with the same "Unable to implement 
EnumerableAggregate", although `MIN(v)` and `ORDER BY v` work on the same data. 
`ArgMinMaxImplementor` compares non-primitive keys with 
`SqlFunctions.ltNullable(Comparable, Comparable)`, and an array is a 
`java.util.List`. That is a separate issue, which I can file, but it shows that 
validation is where the key's comparability has to be decided.
   
   If you still prefer to keep these functions permissive, I can instead reject 
only `VECTOR` keys inside #5331, as it already does for `ORDER BY`, `GROUP BY` 
and the other clauses, and close this PR.


-- 
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