Support EXPLAIN FORMAT JSON for Table Model#17430
Conversation
- Fix ExplainAnalyzeOperator to only instantiate the needed drawer (TEXT or JSON), avoiding wasted work - Replace hand-concatenated JSON in mergeExplainResultsJson with Gson to prevent injection from unescaped CTE names - Add proper imports in PlanGraphJsonPrinter, replace FQN with simple class names - Use JsonArray for list-type properties instead of String.valueOf() - Fix ExplainAnalyze.equals()/hashCode() to include outputFormat and verbose - Add Javadoc to ExplainOutputFormat documenting valid formats per statement - Default MPPQueryContext.explainOutputFormat to TEXT instead of null - Mark old 5-arg ExplainAnalyzeOperator constructor @deprecated - Improve testExplainInvalidFormat to assert on error message content - Add common pitfalls section to CLAUDE.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #17430 +/- ##
============================================
- Coverage 40.68% 40.64% -0.04%
Complexity 2620 2620
============================================
Files 5244 5247 +3
Lines 362374 362809 +435
Branches 46653 46716 +63
============================================
+ Hits 147419 147477 +58
- Misses 214955 215332 +377 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Requires apache/iotdb#17430 to be merged for EXPLAIN (FORMAT JSON) support.
The grammar change added optional '(' FORMAT identifier ')' to EXPLAIN
and EXPLAIN ANALYZE rules, so '(' is now a valid expected token in
parser error messages.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When using EXPLAIN (FORMAT JSON) or EXPLAIN ANALYZE (FORMAT JSON) in the CLI, the JSON content was wrapped in table borders (|), making it hard to copy for visualization. Now the header retains its table border formatting while JSON content lines are printed without '|' borders. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…otes from -e args Java ProcessBuilder escapes internal " with \" but cmd.exe doesn't recognize \" as an escape - it treats every " as a quote toggle. This caused the SQL argument to be split into broken tokens with extra \ chars, producing malformed SQL that the server couldn't parse. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Fix Windows IT failure: wrap -e SQL args in quotes to prevent cmd.exe from misinterpreting semicolons and parentheses in EXPLAIN (FORMAT JSON) commands. 2. Extend PlanGraphJsonPrinterTest with 13 new tests covering OffsetNode, ProjectNode, FilterNode, SortNode, MergeSortNode, ExchangeNode, ExplainAnalyzeNode, JoinNode, UnionNode, OutputNode, and deep plan hierarchies. 3. Add FragmentInstanceStatisticsJsonDrawerTest (11 tests) covering plan statistics, dispatch cost, fragment instances with operator trees, verbose mode, null handling, retry counts, and specifiedInfo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ebugging
The test fails on Windows with "Should find JSON start '{'" but provides
no visibility into what the CLI process actually output. Add full process
output (with line numbers) to every assertion message so failures on CI
can be diagnosed without local reproduction.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…d table names On Windows, the multi-statement SQL "USE db; EXPLAIN (FORMAT JSON) SELECT * FROM t1" gets mangled when passed through cmd.exe → start-cli.bat → java because the batch script doesn't handle -e specially - the SQL goes into PARAMETERS which is expanded without quotes, causing cmd.exe's argument parsing to corrupt the SQL with stray characters (the server parser reported "mismatched input '-'" at position 51). Fix: use fully qualified table names (database.table) instead of "USE db; ..." to avoid the multi-statement ';' separator entirely. Both Unix and Windows tests are updated for consistency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… mangling The \"..\" quoting pattern in -e SQL arguments interacts badly with cmd.exe's quote toggle semantics: the \" causes early quote-off, leaving () exposed as unquoted text where cmd.exe consumes them. This resulted in EXPLAIN (FORMAT JSON) losing its parentheses and having -sql_dialect appended, producing a parse error at position 51. Remove the unnecessary inner quotes from all -e arguments in testOnWindows. ProcessBuilder's standard quoting (wrapping the space-containing arg in "...") works correctly with cmd.exe. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
I found a few functional issues in the new JSON explain path:
EXPLAIN (FORMAT JSON)
WITH cte1 AS MATERIALIZED (SELECT * FROM t)
SELECT * FROM cte1;
|
|




Summary
FORMAToption toEXPLAINandEXPLAIN ANALYZEstatements in the Table Model, allowing users to choose the output format (JSON, GRAPHVIZ, or TEXT)FORMAT JSON, the CLI now prints JSON content without|table borders, so users can directly copy the JSON for visualization. The column header retains its table border formatting.Syntax
Supported formats:
GRAPHVIZTEXTJSONCLI Output Format (FORMAT JSON)
Before (hard to copy JSON due to
|borders):After (JSON content can be directly copied):
Examples
1. EXPLAIN (FORMAT JSON)
2. EXPLAIN ANALYZE (FORMAT JSON)
3. Invalid format produces clear error
Key Design Decisions
|borders, while the column header retains its table formatting.(FORMAT ...)clause is entirely optional.Test Plan
PlanGraphJsonPrinterandExplainFormatTestExplainJsonCliOutputIT): verifies JSON content has no|borders while header retains table formatting