Skip to content

PHOENIX-7919 Support EXPLAIN FORMAT JSON - #2527

Merged
apurtell merged 1 commit into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7919
Jun 13, 2026
Merged

PHOENIX-7919 Support EXPLAIN FORMAT JSON#2527
apurtell merged 1 commit into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7919

Conversation

@apurtell

Copy link
Copy Markdown
Contributor

EXPLAIN (FORMAT JSON) <stmt> returns a single VARCHAR cell whose value is the Jackson serialization of the in-memory ExplainPlanAttributes tree. A new ExplainJsonRenderer owns a private static ObjectWriter configured for the EXPLAIN JSON contract and a DefaultPrettyPrinter whose DefaultIndenter is set on both the object and array indenters, so the output is human readable with two space indentation for both objects and arrays, render(...) wraps JsonProcessingException as SQLException. PhoenixStatement#ExecutableExplainStatement.compilePlan branches on getOptions().getFormat(). TEXT is unchanged. JSON skips renderTopOfPlanText and emits exactly one row carrying the rendered document, with the three plan-total estimate cells attached to the first row. regionLocations populates under (REGIONS, FORMAT JSON) and is null otherwise.

Co-authored-by: Claude Opus 4.8[1m] noreply@anthropic.com

Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>

CopilotAI 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.

Pull request overview

Adds end-to-end support for EXPLAIN (FORMAT JSON) <stmt> by rendering the ExplainPlanAttributes tree as a pretty-printed JSON document and returning it as a single-row result set.

Changes:

  • Introduces ExplainJsonRenderer to serialize ExplainPlanAttributes to pretty-printed JSON (2-space indentation for objects and arrays).
  • Updates PhoenixStatement#ExecutableExplainStatement.compilePlan to branch on ExplainOptions.Format.JSON and return exactly one row for JSON format.
  • Adds a new end-to-end test validating JSON output and the (REGIONS, FORMAT JSON) combination.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

FileDescription
phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainJsonOutputTest.javaNew E2E tests for EXPLAIN (FORMAT JSON) output shape and equivalence to in-process attributes (post-normalization).
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.javaRoutes EXPLAIN rendering based on format; JSON produces a single rendered-document row.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/ExplainJsonRenderer.javaNew renderer encapsulating Jackson configuration for EXPLAIN JSON serialization and pretty-printing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@apurtell

Copy link
Copy Markdown
ContributorAuthor

Test Results

Unit tests

TestTests runFailuresErrorsSkipped
ExplainPlanTest105000
ExplainJsonOutputTest2000
ExplainOptionsParserTest16000
StatementHintsCompilationTest4000
Total127000

Integration tests

TestTests runFailuresErrorsSkipped
ExplainPlanWithStatsEnabledIT30000
ExplainPlanWithStatsDisabledIT17000
Total47000

Notes

  • ExplainJsonOutputTest validates the end-to-end Statement.executeQuery path for both (FORMAT JSON) and (REGIONS, FORMAT JSON): exactly one result-set row, pretty-printed (two-space) indentation present in the raw cell, and deep equality of the normalized JSON against the in-process ExplainPlanAttributes for the same query.
  • regionLocations is elided by ExplainJsonNormalizer, so the (REGIONS, FORMAT JSON) case confirms the combination produces one well-formed JSON row rather than asserting on cluster-specific region content.

@apurtell
apurtell merged commit 3631a0d into apache:PHOENIX-7876-featureJun 13, 2026
@apurtell
apurtell deleted the PHOENIX-7919 branch June 13, 2026 19:54
apurtell added a commit to apurtell/phoenix that referenced this pull request Jun 17, 2026
Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>
asf-gitbox-commits pushed a commit that referenced this pull request Jul 24, 2026
Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>
apurtell added a commit to apurtell/phoenix that referenced this pull request Aug 4, 2026
Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>
Sign up for freeto 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.

2 participants

@apurtell