Skip to content

[ESQL] Greatest and Least can fail with Illegal Data Type on types that resolved correctly #114036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
not-napoleon opened this issue Oct 3, 2024 · 7 comments · May be fixed by #128429
Open
Labels
:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@not-napoleon
Copy link
Member

Related to #113961

resolveType for Greatest and Least only checks that all the input data types are the same (or null). The toEvaluator function, however, has an explicit list of types it maps to evaluators, and if a type does not match we throw from there. Personally, I recommend a strategy like we used in the binary comparisons, where we have a map from data types to evaluators, and resolve types by checking if they are keys in the map. There are probably other solutions as well. The goal is that resolveType should be consistent with toEvaluator with regard to type support.

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Oct 3, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@alex-spies alex-spies added the good first issue low hanging fruit label Jan 20, 2025
@hye-on
Copy link
Contributor

hye-on commented Jan 21, 2025

Hi @not-napoleon Can I take this on?:)

@PawanSuryavanshi95
Copy link

Hi @not-napoleon @alex-spies ,

Is this issue still relevant? If it hasn't been picked up by someone else, I would be happy to work on it.

@jonny5203
Copy link

Hi, are someone currently working on this, I would love to be assigned for this one

@BinhMike
Copy link

Hi @not-napoleon, I am taking on this issue.

@shinsj4653
Copy link

Hi, @not-napoleon. @BinhMike.
If this issue is not currently being worked on, I would be glad to take it over.

@alex-spies alex-spies removed the good first issue low hanging fruit label May 12, 2025
shinsj4653 added a commit to shinsj4653/elasticsearch that referenced this issue May 25, 2025
This commit refactors the Greatest function to use an evaluator map for better
code organization. The changes include:
- Added EVALUATOR_MAP for evaluator factory mapping
- Updated toEvaluator to use map-based lookup
- Added NULL type validation
- Updated error messages to use getWriteableName()

The refactoring improves code readability and maintainability by:
- Replacing if-else chains with a map-based lookup
- Centralizing evaluator factory creation
- Adding consistent NULL type validation
- Using getWriteableName() for error messages

Relates to elastic#114036
shinsj4653 added a commit to shinsj4653/elasticsearch that referenced this issue May 25, 2025
This commit refactors the Least function to use an evaluator map for better
code organization. The changes include:
- Added EVALUATOR_MAP for evaluator factory mapping
- Updated toEvaluator to use map-based lookup
- Added NULL type validation
- Updated error messages to use getWriteableName()

The refactoring improves code readability and maintainability by:
- Replacing if-else chains with a map-based lookup
- Centralizing evaluator factory creation
- Adding consistent NULL type validation
- Using getWriteableName() for error messages

Relates to elastic#114036
shinsj4653 added a commit to shinsj4653/elasticsearch that referenced this issue May 25, 2025
This commit adds test cases for both Greatest and Least functions to verify:
- All supported data types (boolean, double, integer, long, keyword, text, version, ip, datetime, date_nanos)
- NULL value handling
- String comparisons
- Numeric comparisons
- Boolean operations
- Date/time comparisons

The tests ensure that:
- Both functions handle NULL values correctly
- Type validation works as expected
- Evaluator selection is correct for each data type
- Results are computed correctly for all supported types

Relates to elastic#114036
@shinsj4653
Copy link

Hi, @alex-spies @not-napoleon

I've created a PR to refactor the Greatest and Least functions to use an evaluator map: #128429

The changes include:

  • Added EVALUATOR_MAP for evaluator factory mapping
  • Updated toEvaluator to use map-based lookup
  • Added NULL type validation
  • Updated error messages to use getWriteableName()

PTAL when you have time. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
8 participants