Skip to content

Enhance doc and error message handling for bins on time-related fields#4713

Merged
Swiddis merged 7 commits intoopensearch-project:mainfrom
ahkcs:bins_time
Dec 10, 2025
Merged

Enhance doc and error message handling for bins on time-related fields#4713
Swiddis merged 7 commits intoopensearch-project:mainfrom
ahkcs:bins_time

Conversation

@ahkcs
Copy link
Copy Markdown
Collaborator

@ahkcs ahkcs commented Oct 31, 2025

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

@ahkcs ahkcs force-pushed the bins_time branch 3 times, most recently from 4977779 to 3a75657 Compare November 5, 2025 18:46
@ahkcs ahkcs marked this pull request as ready for review November 5, 2025 19:43
@ahkcs ahkcs changed the title Fix bins on time-related fields Enhance doc and error message handling for bins on time-related fields Nov 5, 2025
@ahkcs
Copy link
Copy Markdown
Collaborator Author

ahkcs commented Nov 5, 2025

unit tests in CI seems flaky

noCharger
noCharger previously approved these changes Nov 6, 2025

// 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Describe the default behavior and the configuration that controls pushdown.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated comments and documentation

@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 2 weeks with no activity.

ahkcs added 6 commits December 9, 2025 14:28
…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>
Signed-off-by: Kai Huang <ahkcs@amazon.com>
Signed-off-by: Kai Huang <ahkcs@amazon.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 9, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messaging when using the bins parameter with timestamp fields to provide clearer guidance on pushdown requirements.
  • Documentation

    • Added documentation for bins parameter constraints with timestamp fields, including pushdown enablement prerequisites and proper aggregation bucket configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This 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

Cohort / File(s) Summary
Error Handling & Plan Preparation
core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.java
Added SQLException detection for WIDTH_BUCKET plan preparation errors; throws UnsupportedOperationException with guidance to enable pushdown and use timestamp fields as aggregation buckets
Documentation Updates
docs/user/ppl/cmd/bin.md, core/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java
Expanded documentation detailing bins parameter limitations for timestamp fields, including pushdown enablement requirements and aggregation bucket constraints
Test Coverage
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java, integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.java
Added test method for pushdown-disabled failure scenarios; added test guard method enabledOnlyWhenPushdownIsDisabled() for symmetric precondition checks

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Duplicate test method declaration: The testBinsOnTimeFieldWithPushdownDisabled_ShouldFail() method appears twice in CalciteBinCommandIT.java—verify if this is intentional or requires removal
  • Error message alignment: Cross-check that the exception message in CalciteToolsHelper.java matches the documentation guidance in bin.md
  • Import consistency: Review the dual import of assertThrows from both org.junit.Assert and org.junit.jupiter.api.Assertions in CalciteBinCommandIT.java

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: enhancing documentation and error message handling for the bins parameter when used with time-related fields.
Description check ✅ Passed The description is clearly related to the changeset, explaining that the PR adds error handling and documentation for the bins parameter limitation on timestamp fields.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Kai Huang <ahkcs@amazon.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 docs

The 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 underlying SQLException when wrapping and document workaround

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f963a0 and 2d9da1c.

📒 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: Use PascalCase for class names (e.g., QueryExecutor)
Use camelCase for method and variable names (e.g., executeQuery)
Use UPPER_SNAKE_CASE for 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
Prefer Optional<T> for nullable returns in Java
Avoid unnecessary object creation in loops
Use StringBuilder for 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.java
  • core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.java
  • integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java
  • core/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.java
  • core/src/main/java/org/opensearch/sql/calcite/utils/CalciteToolsHelper.java
  • integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java
  • core/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.java
  • integ-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.java
  • integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java
  • core/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.java suffix 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.java
  • 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: 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.java
  • core/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.java
  • core/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 uses Assume.assumeTrue appropriately 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 limitations

The expanded description and explicit “Limitation” block for bins on 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 appropriate

The new test:

  • Uses enabledOnlyWhenPushdownIsDisabled() to guard execution, matching the new PPL base helper.
  • Asserts a ResponseException and validates that the message contains key phrases about:
    • 'bins' parameter on timestamp fields requires
    • pushdown to be enabled
    • aggregation bucket

This aligns with the new UnsupportedOperationException message in CalciteToolsHelper and the documented limitation. Once the assertThrows import 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 for assertThrows

assertThrows is 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;

@Swiddis Swiddis enabled auto-merge (squash) December 10, 2025 20:18
@Swiddis Swiddis merged commit ef4c51e into opensearch-project:main Dec 10, 2025
38 checks passed
@RyanL1997 RyanL1997 added documentation Improvements or additions to documentation backport 2.19-dev labels Dec 10, 2025
@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

The backport to 2.19-dev failed:

The process '/usr/bin/git' failed with exit code 128

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

Then, create a pull request where the base branch is 2.19-dev and the compare/head branch is backport/backport-4713-to-2.19-dev.

@ahkcs ahkcs deleted the bins_time branch December 10, 2025 20:23
ahkcs added a commit to ahkcs/sql that referenced this pull request Dec 10, 2025
…lds (opensearch-project#4713)

(cherry picked from commit ef4c51e)
Signed-off-by: Kai Huang <ahkcs@amazon.com>
@LantaoJin LantaoJin added the backport-manually Filed a PR to backport manually. label Dec 12, 2025
penghuo pushed a commit that referenced this pull request Dec 15, 2025
…lds (#4713) (#4937)

(cherry picked from commit ef4c51e)

Signed-off-by: Kai Huang <ahkcs@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.19-dev backport-failed backport-manually Filed a PR to backport manually. documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants