Skip to content

Web UI: pretty-print and highlight the value of a selected JSON cell - #118640

Merged
alexey-milovidov merged 8 commits into
masterfrom
play-json-pretty-print
Oct 3, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
play-json-pretty-print

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

In the Web UI (play.html), clicking a cell of a JSON column now shows the value pretty-printed with two-space indentation, one member per line, with keys, strings, numbers and the literals true, false, null highlighted. The compact one-line form is restored when the selection leaves the cell, and stays the value used for copying and filtering.

The pretty form is built lazily for the selected cell only, from the compact text the cell already holds, which is the same on the page's default JSONCompactStrings format (the value arrives as JSON text) and on the JSON format (a parsed object). The expanded overlay of a selected cell is color-inverted, so the pretty-printed block inverts itself back and takes its palette from new --json-* variables defined per theme, modelled on the clickhouse-client colors.

Light theme:

Light theme: a selected JSON cell, pretty-printed and highlighted

Dark theme:

Dark theme: a selected JSON cell, pretty-printed and highlighted

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Web UI: clicking a cell of a JSON column pretty-prints the value with two-space indentation and syntax highlighting.


Workflow [PR]
Sync PR [sync-upstream/pr/118640]

Version info

  • Merged into: 26.10.1.1413-master (included in 26.10 and later)

Clicking a cell of a `JSON` column in `play.html` now shows the value pretty-printed with
two-space indentation, one member per line, with keys, strings, numbers and the literals
`true`, `false`, `null` highlighted. The compact one-line form is restored when the
selection leaves the cell, and stays the value used for copying and filtering.

The pretty form is built lazily for the selected cell only (`_expandJSON`), from the compact
text the cell already holds, which is the same on the page's default `JSONCompactStrings`
format (the value arrives as JSON text) and on the `JSON` format (a parsed object). The
expanded overlay of a selected cell is color-inverted, so the pretty-printed block inverts
itself back and takes its palette from new `--json-*` variables defined per theme.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [afb2e86]

Summary: ✅


AI Review

Summary

This PR adds lazy pretty-printing and syntax highlighting for selected JSON cells in /play, together with runtime and stateless regression coverage for the new rendering path. I reviewed the current diff and all prior discussion threads, verified that the previously raised issues are addressed in the current code, and I do not see a remaining correctness, compatibility, or safety problem in the changed surface.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit afb2e86.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.50% -0.10%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +154 lines in 55 files (-133 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 7, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Sep 7, 2026
Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits September 16, 2026 11:31
A result header can carry the same output name more than once, and both the
row lookup and the per-column type flags are keyed by that name, so a `JSON`
namesake of a non-`JSON` column tagged the latter's cells with `_jsonText`;
selecting one of them then sent plain text through `JSON.parse` in
`_expandJSON`, which threw. Withhold the tag for a duplicated name, the way
sort and filter are already withheld from it (`duplicateColumnNames`), so the
compact form simply stays. The test pins the guarded line.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits September 25, 2026 21:38
…ry lexeme

`prettyPrintJSON` rendered the value after a round trip through `JSON.parse`,
so the selected view could show a different document than the compact cell:
numbers became IEEE-754 doubles (`9007199254740993` shown as
`9007199254740992`, `1e309` as the non-JSON `Infinity`), strings were
re-escaped, a repeated key was dropped and integer-like keys moved first.

It now walks the original text with a small recursive-descent parser that
copies every scalar lexeme verbatim and only changes the whitespace; text that
is not JSON throws a `SyntaxError`, as before.

The new integration test `test_play_json_pretty_print` executes the real
`prettyPrintJSON` from the served page in Node.js (the same setup as
`test_play_result_shaping`) and checks the layout, the verbatim value, the
highlighting spans and the rejection of invalid text; against the previous
implementation 7 of its checks fail.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing afb2e862b with master b466ea8c9 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118640&sha=45040ff94059e5e8e1517a06d189c2878bb81235&name_0=PR&name_1=Stress%20test%20%28arm_release%29 (segmentation fault in ReadFromMerge::createChildrenPlans / getFirstTableExpression, matches #122589) and provide a fix in a separate PR. If the fix is already in progress, link it here. This PR only changes play.html and its tests. The formats_columns_nullable perf regression on arm is also unrelated to this change. Merged the latest master to re-run CI.

@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Investigated. This is STID 2650-47a4, fixed by my #119387 (merged 2026-10-01). The run tested 45040ff9, a master merge from 2026-09-25 without it; your new merge afb2e862 contains it.

The crashed query is the remote side of an internal clusterAllReplicas(...) read of tablefunc11 from 02888_system_tables_with_inaccessible_table_function.sql, received as a serialized plan (TCPHandler: Received query plan). tablefunc11 is CREATE TABLE ... (x String) AS merge(...), a StorageTableFunctionProxy over Merge. The received read was routed by typeid_cast<const StorageMerge *>, which the proxy does not match, so StorageMerge got a null SelectQueryInfo::query and createChildrenPlans dereferenced it (query_info.query->as<ASTSelectQuery>()->sampleSize() -> getFirstTableExpression). #119387 routes by IStorage::readRequiresAnalyzedQuery(), which StorageProxy delegates to the nested table.

Measured with that table and SELECT count() FROM remote('127.0.0.1:<port>', db, tablefunc11) SETTINGS serialize_query_plan = 1, prefer_localhost_replica = 0: a debug build of master 064b09a3 (before #119387) aborts at px != 0 in ReadFromMerge::createChildrenPlans with the same frames as the CI report; master f86ca42b returns 10000, also with parallel_replicas_plan_based = 1, parallel_replicas_allow_merge_tables = 1.

#122589 is a different crash: buildShardCollapseFanOut -> CollectAliasNameTranslationVisitor -> PlannerContext::getColumnNodeIdentifierOrNull, a lazily planned Merge read resolving a correlated column through a PlannerContext that was already freed (STID 4877-28b1). It is fixed by my #122475 (merged 2026-09-27). The issue's build 199f114be9fc predates that merge, and its query is the "scalar subquery inside a subquery in FROM" case of 05258_correlated_subquery_over_merge_nested_planning with a different constant. On an ASan build of master a8693eb6 the exact query from the issue returns 2 with no report.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 3, 2026
Merged via the queue into master with commit 5d1eb5c Oct 3, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the play-json-pretty-print branch October 3, 2026 17:48
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
@clickhouse-gh clickhouse-gh Bot added comp-web-ui Web UI embedded in the server: Play, the dashboards, the merges and processors visualisers, the w... and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-web-ui Web UI embedded in the server: Play, the dashboards, the merges and processors visualisers, the w... pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants