-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[9.0] ESQL: Refactor Greatest and Least functions to use evaluator map (#114036) #128429
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
shinsj4653
wants to merge
5
commits into
elastic:main
Choose a base branch
from
shinsj4653:bugfix/114036-greatest-least-type-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[9.0] ESQL: Refactor Greatest and Least functions to use evaluator map (#114036) #128429
shinsj4653
wants to merge
5
commits into
elastic:main
from
shinsj4653:bugfix/114036-greatest-least-type-resolution
+73
−28
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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
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
Pinging @elastic/es-analytical-engine (Team:Analytics) |
idegtiarenko
reviewed
Jun 3, 2025
throw EsqlIllegalArgumentException.illegalDataType(dataType); | ||
} | ||
|
||
return evaluatorFactory.apply(factories); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is one of the things worth doing with java`s switch? Each data type is enum and compile time constant
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
:Analytics/ES|QL
AKA ESQL
external-contributor
Pull request authored by a developer outside the Elasticsearch team
Team:Analytics
Meta label for analytical engine team (ESQL/Aggs/Geo)
v9.2.0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ESQL: Refactor Greatest and Least functions to use evaluator map
Description
This PR refactors the
Greatest
andLeast
functions to use an evaluator map for better code organization and maintainability. The changes include:EVALUATOR_MAP
to map data types to their corresponding evaluator factoriestoEvaluator
method to use the map instead of if-else chainsChanges
Greatest.java
:EVALUATOR_MAP
for evaluator factory mappingtoEvaluator
to use map-based lookupgetWriteableName()
Least.java
:EVALUATOR_MAP
for evaluator factory mappingtoEvaluator
to use map-based lookupgetWriteableName()
Testing
All existing tests pass (
GreatestTests.java, LeastTests.java
)GreatestTests.java
LeastTests.java
Test coverage includes:
Related Issues
Closes #114036
Checklist
Backport