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

   <!--
   Thanks for sending a pull request! Here are some critical tips for you:
   
   1. READ THE GUIDE FIRST: https://calcite.apache.org/develop/#contributing
      *For significant contributions, please discuss on the dev mailing list or 
Jira BEFORE coding.*
   
   2. JIRA IS USUALLY MANDATORY: Ensure you have created an issue on the 
Calcite Jira:
      https://issues.apache.org/jira/projects/CALCITE/issues
      *Check existing issues first to avoid duplicates.*
      *Note: A Jira is NOT required for typos and cosmetic changes (i.e., 
changes that are neither bugs nor features).*
   
   3. TIMING: Strongly recommended to create the Jira BEFORE you start writing 
code (e.g., a day or so before posting a PR).
      This gives others a chance to weigh in on your specification.
   
   4. CRITICAL CONSISTENCY RULE
      The following three items MUST match exactly in wording and meaning:
      (A) The Jira Issue Title
      (B) This Pull Request Title
      (C) Your Git Commit Message
   
      Format: [CALCITE-XXXX] <Description>
      Example: [CALCITE-0000] Add IF NOT EXISTS clause to CREATE TABLE
   
      Guidelines for a good Title:
      - Illustrate using SQL keywords (in ALL-CAPS) rather than Java method 
names.
      - Focus on the specification and user experience, not the implementation.
      - Make it clear whether it is a bug or a feature.
      - Use words like "should" to indicate desired behavior vs. current 
behavior (e.g., "Validator should not close model file").
   
   5. REPRODUCTION: If fixing a bug, please provide a concise SQL example or 
test case to reproduce the issue for a faster review.
   
   6. TESTING: Ensure `./gradlew build` passes and appropriate tests are 
added/updated.
   -->
   
   ## Jira Link
   
   [CALCITE-7858](https://issues.apache.org/jira/browse/CALCITE-7858)
   
   ## 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)`, `ARG_MAX(value, key)` and their aliases `MIN_BY` and 
`MAX_BY` require the key to be comparable, but the validator accepts a key 
whose type has comparability `NONE`. `MIN` and `MAX` already reject the same 
type.
   
   To reproduce in `SqlValidatorTest`: in the test catalog, 
`EMP_ADDRESS.HOME_ADDRESS` has the structured type `ADDRESS`, whose 
comparability is `NONE`.
   
   ```sql
   select arg_min(empno, home_address) from emp_address
   ```
   
   On `main` this validates, and so do `ARG_MAX`, `MIN_BY` and `MAX_BY` (Spark 
library). With this change, they fail like `MIN(home_address)` does:
   
   ```
   Cannot apply 'ARG_MIN' to arguments of type 'ARG_MIN(<INTEGER>, <>)'. 
Supported form(s): ARG_MIN(<ANY>, <COMPARABLE_TYPE>)
   ```
   
   Cause: `OperandTypes.ANY_COMPARABLE`, the operand type checker of these 
functions (added in CALCITE-5283), returns `false` for a non-comparable key but 
never throws, and `SqlOperator.validateOperands` ignores the returned value. It 
also discards the result of the operand-count check.
   
   Changes:
   
   - `OperandTypes.ANY_COMPARABLE` throws 
`callBinding.newValidationSignatureError()` when the operand count is invalid 
or the key is not comparable and `throwOnFailure` is true; otherwise it returns 
`false`. `SqlOperator.validateOperands` is unchanged.
   - `SqlValidatorTest.testArgMinMaxNonComparableKey` covers the four functions 
with a non-comparable key, and checks that a non-comparable value (the first 
argument) is still accepted.


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