Skip to content

[Backport 3.9] Report a PPL result that covers only some of its shards (#5807) - #5866

Merged
ahkcs merged 1 commit into
opensearch-project:3.9from
ahkcs:backport/backport-5807-to-3.9
Oct 12, 2026
Merged

ahkcs merged 1 commit into
opensearch-project:3.9from
ahkcs:backport/backport-5807-to-3.9

Conversation

@ahkcs

@ahkcs ahkcs commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Backport of #5807 to 3.9. Clean cherry-pick, matches main.

Verified on this branch: spotlessCheck, unit tests for common, core, ppl, opensearch and opensearch-sql-plugin, and :integ-test:compileTestJava.

Related Issues

Backport of #5807

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…roject#5807)

---------

Signed-off-by: Kai Huang <[email protected]>
(cherry picked from commit f48b2b1)
Signed-off-by: Kai Huang <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Possible Issue

Warnings are drained before the timewrap finally block clears the thread-local. If the timewrap block throws an exception, the thread-local is cleared but warnings remain undrained, potentially leaking into the next query on the same thread. Move the drain inside the finally block or after it to ensure warnings are always cleared.

List<Warning> warnings = CalcitePlanContext.drainWarnings();
Possible Issue

The warning is added on the query thread after a background fetch completes. If multiple pages are fetched in rapid succession before warnings are drained, the same partial-result warning could be added multiple times for a single query, contradicting the intent shown in the test at line 158 which expects deduplication. The code does not deduplicate warnings before adding them.

response.getShardStats().toWarning().ifPresent(CalcitePlanContext::addWarning);

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Drain warnings after timewrap processing

Draining warnings before the timewrap block means any warnings added during timewrap
processing will be lost. If TimewrapPivot operations could generate warnings, they
won't be captured. Consider draining warnings after the timewrap block completes to
ensure all warnings are collected.

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/OpenSearchExecutionEngine.java [476-492]

-List<Warning> warnings = CalcitePlanContext.drainWarnings();
-
 // Timewrap post-processing: pivot unpivoted rows into period columns. The pivot is shared with
 // the analytics route (AnalyticsExecutionEngine) so both engines produce identical output.
 if (TimewrapPivot.isTimewrap()) {
   try {
     ...
   } finally {
     CalcitePlanContext.clearTimewrapSignals();
   }
 }
 
+List<Warning> warnings = CalcitePlanContext.drainWarnings();
+
Suggestion importance[1-10]: 7

__

Why: Valid concern about warning collection timing. If TimewrapPivot operations could generate warnings, draining before the block would lose them. However, the PR comment explicitly states draining before the block to avoid interference with clearTimewrapSignals(), suggesting this is intentional design.

Medium
Handle zero total shards case

The missing() calculation may incorrectly report missing shards when total is zero
(e.g., for UNKNOWN stats). This could lead to false positives in partial result
detection. Consider adding a guard to return 0 when total is 0, or verify that
UNKNOWN stats never trigger warnings through isComplete().

opensearch/src/main/java/org/opensearch/sql/opensearch/response/ShardStats.java [61-63]

 public int missing() {
+  if (total == 0) {
+    return 0;
+  }
   return Math.max(0, total - successful - failed);
 }
Suggestion importance[1-10]: 3

__

Why: The suggestion addresses a potential edge case where total is zero. However, UNKNOWN is defined with total=0 and isComplete() already returns true for it (since timedOut=false, failed=0, and missing()=0), so no false positives occur. The Math.max(0, ...) already handles negative results safely.

Low

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.91%. Comparing base (bb7514f) to head (88925cf).
⚠️ Report is 1 commits behind head on 3.9.

Files with missing lines Patch % Lines
...opensearch/sql/opensearch/response/ShardStats.java 93.22% 2 Missing and 2 partials ⚠️
...opensearch/executor/OpenSearchExecutionEngine.java 0.00% 2 Missing ⚠️

❌ Your project check has failed because the head coverage (62.91%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##                3.9    #5866      +/-   ##
============================================
+ Coverage     62.86%   62.91%   +0.04%     
- Complexity     8782     8808      +26     
============================================
  Files           938      939       +1     
  Lines         40145    40209      +64     
  Branches       4519     4526       +7     
============================================
+ Hits          25238    25297      +59     
- Misses        14106    14109       +3     
- Partials        801      803       +2     
Flag Coverage Δ
sql-engine 62.91% <90.90%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ahkcs
ahkcs merged commit d62098c into opensearch-project:3.9 Oct 12, 2026
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants