Enhance doc and error message handling for bins on time-related fields#4713
Enhance doc and error message handling for bins on time-related fields#4713Swiddis merged 7 commits intoopensearch-project:mainfrom
bins on time-related fields#4713Conversation
4977779 to
3a75657
Compare
bins on time-related fieldsbins on time-related fields
|
unit tests in CI seems flaky |
|
|
||
| // Create validated binnable field (validates that field is numeric or time-based) | ||
| // Note: bins parameter works with both numeric and time-based fields | ||
| // Note: bins parameter on time-based fields requires pushdown to be enabled |
There was a problem hiding this comment.
Nit: Describe the default behavior and the configuration that controls pushdown.
There was a problem hiding this comment.
Updated comments and documentation
|
This PR is stalled because it has been open for 2 weeks with no activity. |
…d fields with pushdown disabled Signed-off-by: Kai Huang <ahkcs@amazon.com>
Signed-off-by: Kai Huang <ahkcs@amazon.com>
Signed-off-by: Kai Huang <ahkcs@amazon.com>
Signed-off-by: Kai Huang <ahkcs@amazon.com>
📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughThis PR adds error handling for WIDTH_BUCKET plan preparation failures in Calcite, introduces limitations documentation for the bins command with timestamp fields, and adds test coverage for pushdown-disabled scenarios. Changes span error detection logic, documentation updates, and test utilities. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Signed-off-by: Kai Huang <ahkcs@amazon.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
core/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java (1)
31-35: Align comment terminology with user-facing docsThe comment refers to “time-based fields” while the error message and user docs call out “timestamp fields” specifically. To avoid confusion for maintainers, consider tightening this to “timestamp fields” (or explicitly listing supported time types) so all layers use the same wording for this limitation.
core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.java (1)
363-373: Preserve underlyingSQLExceptionwhen wrapping and document workaroundThe targeted check on
"Error while preparing plan"+"WIDTH_BUCKET"is a reasonable Calcite-specific workaround with a good user-facing message. Two small improvements:
- Wrap the original exception as the cause so debugging retains full context:
- throw new UnsupportedOperationException( - "The 'bins' parameter on timestamp fields requires: (1) pushdown to be enabled" - + " (controlled by plugins.calcite.pushdown.enabled, enabled by default), and" - + " (2) the timestamp field to be used as an aggregation bucket (e.g., 'stats" - + " count() by @timestamp')."); + throw new UnsupportedOperationException( + "The 'bins' parameter on timestamp fields requires: (1) pushdown to be enabled" + + " (controlled by plugins.calcite.pushdown.enabled, enabled by default), and" + + " (2) the timestamp field to be used as an aggregation bucket (e.g., 'stats" + + " count() by @timestamp').", + e);
- Optionally add a brief comment above this block referencing the related Calcite/binning limitation (e.g., issue ID) so future maintainers know why we’re pattern-matching on the message.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.java(1 hunks)core/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java(1 hunks)docs/user/ppl/cmd/bin.md(1 hunks)integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java(2 hunks)integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.java(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.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:
integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.javacore/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.javainteg-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.javacore/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.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:
integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.javacore/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.javainteg-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.javacore/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java
**/test/**/*.java
⚙️ CodeRabbit configuration file
**/test/**/*.java: - Verify test coverage for new business logic
- Check test naming follows conventions (*Test.java for unit, *IT.java for integration)
- Ensure tests are independent and don't rely on execution order
- Validate meaningful test data that reflects real-world scenarios
- Check for proper cleanup of test resources
Files:
integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.javainteg-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.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:
integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.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/utils/CalciteToolsHelper.javainteg-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.javacore/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java
integ-test/**/*IT.java
📄 CodeRabbit inference engine (.rules/REVIEW_GUIDELINES.md)
End-to-end scenarios need integration tests in
integ-test/module
Files:
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java
⚙️ CodeRabbit configuration file
integ-test/**/*IT.java: - Verify integration tests are in correct module (integ-test/)
- Check tests can be run with ./gradlew :integ-test:integTest
- Ensure proper test data setup and teardown
- Validate end-to-end scenario coverage
Files:
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java
**/*IT.java
📄 CodeRabbit inference engine (.rules/REVIEW_GUIDELINES.md)
Name integration tests with
*IT.javasuffix in OpenSearch SQL
Files:
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: opensearch-project/sql PR: 0
File: .rules/REVIEW_GUIDELINES.md:0-0
Timestamp: 2025-12-02T17:27:55.938Z
Learning: Test SQL generation and optimization paths for Calcite integration changes
📚 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: Test SQL generation and optimization paths for Calcite integration changes
Applied to files:
core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.javainteg-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.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: Applies to **/*.java : Document Calcite-specific workarounds in code
Applied to files:
core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.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: Encourage meaningful error messages in code reviews
Applied to files:
core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.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: Applies to **/*IT.java : Name integration tests with `*IT.java` suffix in OpenSearch SQL
Applied to files:
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.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: Code should be clear through naming and structure, not comments
Applied to files:
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.javacore/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.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: Avoid comments that merely restate what the code does
Applied to files:
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.javacore/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java
⏰ 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). (28)
- GitHub Check: bwc-tests-rolling-upgrade (21)
- GitHub Check: bwc-tests-full-restart (25)
- GitHub Check: build-linux (25, integration)
- GitHub Check: build-linux (25, doc)
- GitHub Check: bwc-tests-full-restart (21)
- GitHub Check: build-linux (21, doc)
- GitHub Check: build-linux (25, unit)
- GitHub Check: build-linux (21, unit)
- GitHub Check: build-linux (21, integration)
- GitHub Check: bwc-tests-rolling-upgrade (25)
- GitHub Check: security-it-linux (25)
- GitHub Check: security-it-linux (21)
- GitHub Check: security-it-windows-macos (windows-latest, 25)
- GitHub Check: security-it-windows-macos (macos-14, 25)
- GitHub Check: security-it-windows-macos (windows-latest, 21)
- GitHub Check: security-it-windows-macos (macos-14, 21)
- GitHub Check: build-windows-macos (macos-14, 21, unit)
- GitHub Check: build-windows-macos (macos-14, 25, doc)
- GitHub Check: build-windows-macos (macos-14, 25, unit)
- GitHub Check: build-windows-macos (macos-14, 25, integration)
- GitHub Check: build-windows-macos (windows-latest, 25, -PbuildPlatform=windows, unit)
- GitHub Check: build-windows-macos (windows-latest, 21, -PbuildPlatform=windows, unit)
- GitHub Check: build-windows-macos (macos-14, 21, doc)
- GitHub Check: build-windows-macos (macos-14, 21, integration)
- GitHub Check: build-windows-macos (windows-latest, 25, -PbuildPlatform=windows, integration)
- GitHub Check: build-windows-macos (windows-latest, 21, -PbuildPlatform=windows, integration)
- GitHub Check: CodeQL-Scan (java)
- GitHub Check: test-sql-cli-integration (21)
🔇 Additional comments (4)
integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.java (1)
326-328: Symmetric pushdown-disabled guard looks good
enabledOnlyWhenPushdownIsDisabled()cleanly mirrors the existing enabled-only guard and usesAssume.assumeTrueappropriately to skip tests when the cluster isn’t in the expected state.docs/user/ppl/cmd/bin.md (1)
23-28: Docs accurately capture timestamp + bins limitationsThe expanded description and explicit “Limitation” block for
binson timestamp fields (pushdown requirement and aggregation-bucket usage) are clear and aligned with the runtime behavior and tests.integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java (2)
992-1017: New pushdown-disabled bins-on-timestamp test is appropriateThe new test:
- Uses
enabledOnlyWhenPushdownIsDisabled()to guard execution, matching the new PPL base helper.- Asserts a
ResponseExceptionand validates that the message contains key phrases about:
'bins' parameter on timestamp fields requirespushdown to be enabledaggregation bucketThis aligns with the new
UnsupportedOperationExceptionmessage inCalciteToolsHelperand the documented limitation. Once theassertThrowsimport ambiguity is resolved, the test logic itself looks solid.After fixing the imports, please confirm this test passes in an environment where Calcite is enabled and pushdown is explicitly disabled so the guard doesn’t skip it.
8-11: Fix ambiguous static import forassertThrows
assertThrowsis statically imported from both JUnit 4 and JUnit Jupiter:import static org.junit.Assert.assertThrows; ... import static org.junit.jupiter.api.Assertions.assertThrows;This causes a compilation error due to ambiguous method reference. Remove the JUnit 4 import and keep only the JUnit Jupiter version:
-import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
|
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-4713-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 ef4c51e0e15e6d8e5385ea3605c536775396fc39
# Push it to GitHub
git push --set-upstream origin backport/backport-4713-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 |
…lds (opensearch-project#4713) (cherry picked from commit ef4c51e) Signed-off-by: Kai Huang <ahkcs@amazon.com>
Description
Summary
This PR adds clear error handling and documentation for the known limitation that the bins parameter on timestamp fields requires pushdown to be enabled.
Related Issues
bincommand fails with param bins on time-related fields #4578