Skip to content

Fix SemanticCheckException not thrown#5239

Merged
Swiddis merged 2 commits into
opensearch-project:mainfrom
sunil9977:issue-917
May 19, 2026
Merged

Fix SemanticCheckException not thrown#5239
Swiddis merged 2 commits into
opensearch-project:mainfrom
sunil9977:issue-917

Conversation

@sunil9977

Copy link
Copy Markdown
Contributor

Issue #917 -
Fix SemanticCheckException not thrown for invalid field in nested function

Signed-off-by: Sunil Ramchandra Pawar <pawar_sr@apple.com>
@github-actions

github-actions Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 12d55fe)

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

Isolated Environment

The pushIsolated() method creates a new TypeEnvironment with a null parent. This means any lookup that traverses the parent chain will fail or behave differently than before. It should be validated that all callers of peek() and resolve() after pushIsolated() do not inadvertently require access to parent environment entries (e.g., for subqueries or nested expressions that still need outer scope resolution).

public void pushIsolated() {
  environment = new TypeEnvironment(null);
}
Missing pop()

The previous context.push() was presumably paired with a corresponding context.pop() elsewhere. The new context.pushIsolated() should also be paired with a pop() to avoid leaking the isolated environment onto the stack for subsequent operations. Verify that the environment pushed here is properly cleaned up after the project node is fully processed.

context.pushIsolated();
TypeEnvironment newEnv = context.peek();

@github-actions

github-actions Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Latest suggestions up to 12d55fe
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Isolated push breaks environment restoration on pop

The pushIsolated method replaces the current environment without saving a reference
to it, making it impossible to pop() back to the previous environment later. The
pop() method relies on getParent() to restore the previous environment, but since
the new isolated environment has null as parent, calling pop() after pushIsolated()
will set environment to null, losing the prior context entirely. Consider storing
the previous environment so it can be restored, or documenting that pop() must not
be called after pushIsolated().

core/src/main/java/org/opensearch/sql/analysis/AnalysisContext.java [76-78]

 public void pushIsolated() {
-  environment = new TypeEnvironment(null);
+  // Store previous environment as a non-accessible parent reference
+  // so that pop() can still restore it correctly
+  environment = new TypeEnvironment(null) {
+    private final TypeEnvironment previous = environment;
+    @Override
+    public TypeEnvironment getParent() {
+      return previous;
+    }
+  };
 }
Suggestion importance[1-10]: 6

__

Why: The concern is valid - calling pop() after pushIsolated() will set environment to null since the isolated environment has no parent. However, the PR's intent appears to be specifically to create an isolated environment without parent access (as stated in the Javadoc), and the improved_code uses an anonymous class override which is a somewhat hacky solution. The actual behavior concern is real but the fix approach is questionable.

Low

Previous suggestions

Suggestions up to commit e6e9737
CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve previous environment for correct pop restoration

The pushIsolated method creates a new environment with null as the parent, but it
doesn't save the previous environment anywhere. This means the previous environment
is lost and cannot be restored via pop(), since pop() will set environment to null
(the parent of the new isolated env). Consider storing the previous environment as a
field or passing it differently so pop() can correctly restore it.

core/src/main/java/org/opensearch/sql/analysis/AnalysisContext.java [78-80]

 public void pushIsolated() {
-  environment = new TypeEnvironment(null);
+  environment = new TypeEnvironment(null) {
+    private final TypeEnvironment previousEnv = environment;
+    @Override
+    public TypeEnvironment getParent() {
+      return previousEnv;
+    }
+  };
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that pushIsolated() with null parent will cause pop() to set environment to null, potentially breaking subsequent operations. However, the proposed fix using an anonymous class override is unconventional and may conflict with the intended "isolated" semantics of the method. The issue is real but the fix approach is debatable.

Medium

@Swiddis Swiddis added the infrastructure Changes to infrastructure, testing, CI/CD, pipelines, etc. label Mar 24, 2026
@Swiddis

Swiddis commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

Spotless check is failing in unit CI (./gradlew spotlessApply)

@Swiddis Swiddis moved this to Active in Error Enhancements Mar 31, 2026
@Swiddis Swiddis self-assigned this Mar 31, 2026
@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

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

@Swiddis Swiddis added ci-failure PR blocked due to failing CI and removed stalled labels Apr 21, 2026
@Swiddis

Swiddis commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Bump: CI failure, if not updated by the next stalled cycle will close

Signed-off-by: Sunil Ramchandra Pawar <pawar_sr@apple.com>
@sunil9977 sunil9977 requested a review from songkant-aws as a code owner April 22, 2026 06:10
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 12d55fe

@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

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

@ahkcs

ahkcs commented May 12, 2026

Copy link
Copy Markdown
Collaborator

@sunil9977 are you still tracking this?

@ahkcs ahkcs closed this May 12, 2026
@github-project-automation github-project-automation Bot moved this from Active to Done in Error Enhancements May 12, 2026
@ahkcs ahkcs reopened this May 12, 2026
@sunil9977

Copy link
Copy Markdown
Contributor Author

Yes, I'm looking for the reviewers.

@Swiddis Swiddis enabled auto-merge (squash) May 19, 2026 17:36
@Swiddis Swiddis merged commit dcdb5ba into opensearch-project:main May 19, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-failure PR blocked due to failing CI infrastructure Changes to infrastructure, testing, CI/CD, pipelines, etc. stalled

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants