Add scalar min/max to BuiltinFunctionName#4967
Add scalar min/max to BuiltinFunctionName#4967LantaoJin merged 1 commit intoopensearch-project:mainfrom
Conversation
Signed-off-by: Lantao Jin <ltjin@amazon.com>
📝 WalkthroughWalkthroughThe changes introduce distinct enum entries for scalar MIN/MAX functions and update PPL function registration and translation mappings to use these specialized names instead of shared aggregation function names, preventing naming conflicts during PPL-to-SQL translation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java (1)
61-63: SCALAR_MAX/MIN enum entries are consistent; consider visibility intentDefining
SCALAR_MAX(FunctionName.of("scalar_max"))andSCALAR_MIN(FunctionName.of("scalar_min"))and keeping aggregation/window mappings pointing atMAX/MINpreserves aggregate behavior while enabling separate scalar wiring through these new names.If
scalar_max/scalar_minare intended to be purely internal implementation details for PPL eval (never user‑facing as function names), consider marking them as internal (truein the enum constructor) so they don’t show up in generic function listings that rely onALL_NATIVE_FUNCTIONS.Also applies to: 367-424
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java(1 hunks)core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java(1 hunks)core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java(2 hunks)ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.java
📄 CodeRabbit inference engine (.rules/REVIEW_GUIDELINES.md)
**/*.java: UsePascalCasefor class names (e.g.,QueryExecutor)
UsecamelCasefor method and variable names (e.g.,executeQuery)
UseUPPER_SNAKE_CASEfor constants (e.g.,MAX_RETRY_COUNT)
Keep methods under 20 lines with single responsibility
All public classes and methods must have proper JavaDoc
Use specific exception types with meaningful messages for error handling
PreferOptional<T>for nullable returns in Java
Avoid unnecessary object creation in loops
UseStringBuilderfor string concatenation in loops
Validate all user inputs, especially queries
Sanitize data before logging to prevent injection attacks
Use try-with-resources for proper resource cleanup in Java
Maintain Java 11 compatibility when possible for OpenSearch 2.x
Document Calcite-specific workarounds in code
Files:
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.javacore/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.javappl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.javacore/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java
⚙️ CodeRabbit configuration file
**/*.java: - Verify Java naming conventions (PascalCase for classes, camelCase for methods/variables)
- Check for proper JavaDoc on public classes and methods
- Flag redundant comments that restate obvious code
- Ensure methods are under 20 lines with single responsibility
- Verify proper error handling with specific exception types
- Check for Optional usage instead of null returns
- Validate proper use of try-with-resources for resource management
Files:
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.javacore/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.javappl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.javacore/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java
**/ppl/**/*.java
⚙️ CodeRabbit configuration file
**/ppl/**/*.java: - For PPL parser changes, verify grammar tests with positive/negative cases
- Check AST generation for new syntax
- Ensure corresponding AST builder classes are updated
- Validate edge cases and boundary conditions
Files:
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
**/calcite/**/*.java
⚙️ CodeRabbit configuration file
**/calcite/**/*.java: - Follow existing patterns in CalciteRelNodeVisitor and CalciteRexNodeVisitor
- Verify SQL generation and optimization paths
- Document any Calcite-specific workarounds
- Test compatibility with Calcite version constraints
Files:
core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java
🧠 Learnings (2)
📚 Learning: 2025-12-02T17:27:55.938Z
Learnt from: CR
Repo: opensearch-project/sql PR: 0
File: .rules/REVIEW_GUIDELINES.md:0-0
Timestamp: 2025-12-02T17:27:55.938Z
Learning: Update corresponding AST builder classes when making PPL grammar changes
Applied to files:
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
📚 Learning: 2025-12-02T17:27:55.938Z
Learnt from: CR
Repo: opensearch-project/sql PR: 0
File: .rules/REVIEW_GUIDELINES.md:0-0
Timestamp: 2025-12-02T17:27:55.938Z
Learning: Follow existing patterns in `CalciteRelNodeVisitor` and `CalciteRexNodeVisitor` for Calcite integration
Applied to files:
core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java
🧬 Code graph analysis (1)
core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java (1)
core/src/main/java/org/opensearch/sql/expression/function/PPLBuiltinOperators.java (1)
PPLBuiltinOperators(110-512)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build-windows-macos (windows-latest, 21, -PbuildPlatform=windows, integration)
- GitHub Check: build-windows-macos (windows-latest, 25, -PbuildPlatform=windows, integration)
- GitHub Check: build-windows-macos (macos-14, 21, integration)
🔇 Additional comments (2)
core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java (1)
189-190: Scalar MAX/MIN registration correctly routed through dedicated operatorsUsing
SCALAR_MAX/SCALAR_MINhere and wiring them toPPLBuiltinOperators.SCALAR_MAX/SCALAR_MINcleanly separates scalar eval calls from aggregateMAX/MIN, without touching the aggregate registry. This is consistent with the new enum entries and should resolve the name collision issue described in the linked bug.Also applies to: 873-875
core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java (1)
2906-2919: UsingofAggregationhere correctly isolates aggregate MIN/MAX from scalar variantsSwitching to
BuiltinFunctionName.ofAggregation(aggFunctionName)inbuildAggCallensures chart/timechart secondary aggregations always resolvemin/maxthrough the aggregate mapping, preventing collisions with the new scalarSCALAR_MIN/SCALAR_MAX. The existing switch logic for MIN/EARLIEST, MAX/LATEST, AVG, and the default sum path remains intact and correct.
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
Show resolved
Hide resolved
| private AggCall buildAggCall(RelBuilder relBuilder, String aggFunctionName, RexNode node) { | ||
| BuiltinFunctionName aggFunction = | ||
| BuiltinFunctionName.of(aggFunctionName) | ||
| BuiltinFunctionName.ofAggregation(aggFunctionName) |
There was a problem hiding this comment.
Can you please kindly add a javadoc on BuiltinFunctionName.of to instruct future developers to use BuiltinFunctionName.ofAggregation for aggregation functions?
|
The backport to To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.19-dev 2.19-dev
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.19-dev
# Create a new branch
git switch --create backport/backport-4967-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 7dfabcea94952ead0a27463d810097d74446acc4
# Push it to GitHub
git push --set-upstream origin backport/backport-4967-to-2.19-dev
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.19-devThen, create a pull request where the |
Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit 7dfabce)
Description
Add scalar min/max to BuiltinFunctionName.
Since parsing min/max aggregation function and scalar function (eval function) in AST parser are separated, we can use different names in
BuiltinFunctionNamewith no changes in PPL interface/syntax.eval a = max(b)-> SCALAR_MAXstats max(b)/eventstats max(b)/streamstats max(b)-> (AGG) MAXRelated Issues
Resolves #4774
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.