Skip to content

Fix SQL explain API rejecting ?format=json parameter#5607

Open
gingeekrishna wants to merge 1 commit into
opensearch-project:mainfrom
gingeekrishna:fix/4373-explain-api-json-format
Open

Fix SQL explain API rejecting ?format=json parameter#5607
gingeekrishna wants to merge 1 commit into
opensearch-project:mainfrom
gingeekrishna:fix/4373-explain-api-json-format

Conversation

@gingeekrishna

Copy link
Copy Markdown
Contributor

Description

Fixes #4373

Problem: Since OpenSearch 3.0, calling POST /_plugins/_sql/_explain?format=json returns:

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Failed to create executor due to unknown response format: json",
    "type": "IllegalArgumentException"
  },
  "status": 400
}

Root cause: isSupportedExplainFormat() in SQLQueryRequest.java only accepted "simple", "standard", "extended", and "cost""json" was never in the list. The explain endpoint itself always returns JSON unconditionally (the format parameter has no effect on the response), so "json" was effectively accepted before this validation was tightened.

Fix: Add "json" to isSupportedExplainFormat(). The explain response path in SQLPlugin.java uses JsonResponseFormatter<ExplainResponse> regardless of the format parameter, so this is a pure backward-compatibility fix with no behavioral change.

Changes

  • sql/src/main/java/.../SQLQueryRequest.java — add "json" to isSupportedExplainFormat()
  • sql/src/test/java/.../SQLQueryRequestTest.java — regression test asserting ?format=json is accepted on explain requests

Testing

29/29 tests pass in SQLQueryRequestTest.

isSupportedExplainFormat() only accepted "simple", "standard",
"extended", and "cost" — excluding "json". Before OpenSearch 3.0,
?format=json was valid for the explain endpoint, so existing workflows
that pass this parameter now receive:
  "Failed to create executor due to unknown response format: json"

The explain endpoint already returns JSON unconditionally regardless of
the format parameter, so accepting "json" is a pure backward-
compatibility restoration with no behavioral change.

Fixes opensearch-project#4373

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 5, 2026

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
⚡ No major issues detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Deprecation of OpenSearch DSL format has affected the behavior of the explain API

2 participants