Skip to content

ClickHouse#81794 Pretty print JSON columns in Vertical format#88524

Merged
alexey-milovidov merged 7 commits intoClickHouse:masterfrom
FRosner:frosner/81794
Oct 19, 2025
Merged

ClickHouse#81794 Pretty print JSON columns in Vertical format#88524
alexey-milovidov merged 7 commits intoClickHouse:masterfrom
FRosner:frosner/81794

Conversation

@FRosner
Copy link
Copy Markdown
Contributor

@FRosner FRosner commented Oct 14, 2025

Changelog category (leave one):

  • Improvement

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

JSON columns are now pretty printed when using Vertical format. Closes #81794.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Test Execution

foo@bar:~/projects/ClickHouse$ PATH=~/projects/ClickHouse/build/programs:$PATH tests/clickhouse-test 03700_vertical_format_pretty_print_json
Using queries from '/Users/frosner/projects/ClickHouse/tests/queries' directory
Connecting to ClickHouse server... OK
Connected to server 25.10.1.1 @ cab1c8b9ff3b357d4b922f5930b5c746829d53e4 frosner/81794
Found 1 parallel tests and 0 sequential tests
Running about 1 stateless tests (Process-3).
03700_vertical_format_pretty_print_json:                                [ OK ] 0.30 sec.

1 tests passed. 0 tests skipped. 0.34 s elapsed (Process-3).                                                                                                                                      
All tests have finished.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 14, 2025

CLA assistant check
All committers have signed the CLA.

@FRosner FRosner marked this pull request as ready for review October 17, 2025 20:27
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 17, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Oct 17, 2025

Workflow [PR], commit [95c2885]

Summary:

job_name test_name status info comment
Integration tests (arm_binary, distributed plan, 1/4) failure
test_keeper_three_nodes_two_alive/test.py::test_restart_third_node FAIL cidb

@clickhouse-gh clickhouse-gh bot added the pr-improvement Pull request with some product improvements label Oct 17, 2025
if (col.isNullAt(row_num))
serializeNullJSON(ostr);
else
else if (settings.pretty.charset == FormatSettings::Pretty::Charset::UTF8) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

charset is not the best switch for this. It should be controlled by a new setting in FormatFactorySettings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks strange anyway. Shouldn't it be a separate method, SerializationNullable::serializeTextJSONPretty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

charset is not the best switch for this. It should be controlled by a new setting in FormatFactorySettings.

Yeah I copied that from

if (settings.pretty.charset == FormatSettings::Pretty::Charset::UTF8)
and it appears to be used in other places as well. We could introduce a new property in this PR if you want?

This looks strange anyway. Shouldn't it be a separate method, SerializationNullable::serializeTextJSONPretty?

Yeah, let's do that. It was pretty much duplicated but it's more consistent.

Here it goes: d462932

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

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

The change is generally good!

──────
id: 2
data: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting why do we print an empty line?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or pass the indent that will make it roughly aligned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting why do we print an empty line?

if (pretty)
writeCString("{\n", ostr);
else
writeChar('{', ostr);

if (pretty)
{
writeChar('\n', ostr);
for (size_t i = 0; i != current_prefix.elements.size(); ++i)
{
writeChar(settings.json.pretty_print_indent, (indent + current_prefix.size() - i) * settings.json.pretty_print_indent_multiplier, ostr);
writeCString("}\n", ostr);
}
writeChar(settings.json.pretty_print_indent, indent * settings.json.pretty_print_indent_multiplier, ostr);
writeChar('}', ostr);
}

Do you want me to change that here, too? It might be a bit out of scope for this LHF issue, wdyt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's ok, let's keep it as is.

@alexey-milovidov alexey-milovidov self-assigned this Oct 17, 2025
@FRosner
Copy link
Copy Markdown
Contributor Author

FRosner commented Oct 18, 2025

There are some failing tests that seem unrelated? Are those expeted to be green?

@alexey-milovidov alexey-milovidov merged commit 12141b4 into ClickHouse:master Oct 19, 2025
120 of 123 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 19, 2025
@darkleaf
Copy link
Copy Markdown
Contributor

darkleaf commented Nov 5, 2025

@FRosner this breaks our CI. Could you please add a setting for the feature? Then we could use SETTINGS compatibility='25.3' to preserve old behavior while we support 25.3.

@FRosner
Copy link
Copy Markdown
Contributor Author

FRosner commented Nov 5, 2025

Could you please add a setting for the feature? Then we could use SETTINGS compatibility='25.3' to preserve old behavior while we support 25.3.

Oops! Sorry. Which CI is broken how? Can you elaborate?

@KGOH
Copy link
Copy Markdown

KGOH commented Nov 5, 2025

@FRosner (I'll answer for @darkleaf): our regression tests assert output in Vertical format, which supposedly after this PR includes pretty printed jsons
Since our tests run at multiple clickhouse versions, e.g. at 25.3 and at latest, now with the newer latest this makes the results to be different on different versions which fails our assertions on CI:
image

@darkleaf
Copy link
Copy Markdown
Contributor

darkleaf commented Nov 5, 2025

We test our product against 25.3 and latest.
And we use snapshots to test our inserts.
The snapshot is a text file produced by select ... from ... format Vertical
We expect that this snapshots are equal for all supported versions.

Снимок экрана 2025-11-05 в 14 55 23

@FRosner
Copy link
Copy Markdown
Contributor Author

FRosner commented Nov 5, 2025

Thanks for the context. I'm not the one to decide how to handle this (this is my first contribution and I'm not working for ClickHouse at this point), so I'll let @alexey-milovidov or someone else decide.

If anyone wants my 2 cents, though: Parsing an output format that is documented to be "only appropriate for outputting a query result, but not for parsing" might not be ideal. Why are you relying on vertical output format? Can't you use another format that is meant to be machine-readable?

@darkleaf
Copy link
Copy Markdown
Contributor

darkleaf commented Nov 5, 2025

Why are you relying on vertical output format? Can't you use another format that is meant to be machine-readable?

Our team members read this files on code review, so it should be human readable. We don't parse, we only diff it.

I’d be glad to see a setting similar to these.

@alexey-milovidov
Copy link
Copy Markdown
Member

I'd prefer if @darkleaf would introduce the required setting in a separate pull request.

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

Labels

can be tested Allows running workflows for external contributors 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.

Vertical format should pretty-print JSON

6 participants