Named tuples pretty format#91779
Conversation
|
Workflow [PR], commit [abbb03d] Summary: ❌
|
|
Test failures are expected since the display of named tuples has changed. Should we update the tests to match the new output, or what do you think? @nihalzp |
There was a problem hiding this comment.
Pull request overview
This PR adds support for formatting named tuples as pretty-printed JSON in ClickHouse's Pretty format output. When a named tuple is displayed in Pretty format, it now appears as indented JSON instead of the traditional tuple representation with parentheses, making nested structures more readable.
Key Changes:
- Named tuples in Pretty format are now rendered as formatted JSON objects
- Added
is_pretty_formatflag to FormatSettings to control this behavior - Modified the SerializationTuple class to use JSON serialization when Pretty format is detected
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/03727_named_tuples_pretty_format.sql | Test case with nested named tuples and various data types |
| tests/queries/0_stateless/03727_named_tuples_pretty_format.reference | Expected output showing the pretty-printed JSON format |
| src/Processors/Formats/Impl/PrettyBlockOutputFormat.h | Changed format_settings from const to non-const to allow modification |
| src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp | Initialize format settings to enable pretty printing for JSON |
| src/Formats/FormatSettings.h | Added is_pretty_format boolean flag |
| src/DataTypes/Serializations/SerializationTuple.cpp | Modified serializeText to use JSON serialization for named tuples in Pretty format |
|
|
||
| void SerializationTuple::serializeTextJSONPretty(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings, size_t indent) const | ||
| { | ||
|
|
There was a problem hiding this comment.
Remove unnecessary blank line that adds no value to code readability.
| if (settings.json.write_named_tuples_as_objects | ||
| && has_explicit_names) | ||
| { | ||
|
|
There was a problem hiding this comment.
Remove trailing whitespace that serves no purpose.
In these cases, I think it's safer to add a new setting to use a new option in Format Settings to be able to choose to fallback to previous behavior. We set the new behavior by default, but allow these old tests (or people relying on previous behavior) to use the current output. Please choose a descriptive name for the format option and document it accordingly. Also pay attention to the Style check job that failed. |
There is a case where the test failed because of a difference in width (may be this width is terminal or environment dependent). Do you think I should add an option like max_padding_width? @pamarcos |
I think it was due to how the rows were glued together. It might have been because of block size or even timing issues in that particular CI run. Let me add a commit to swap to PrettyMonoBlock instead to make sure we always buffer and glue them together. I'll also merge master on top to make sure we're running the latest. I ran |
Remove trailing whitespaces added by GitHub web UI when solving the merge conflict
|
Thanks for working on this, @Sasao4o. Appreciate it 🫶 |
686e6fc
|
@pamarcos, On the screenshots and in examples, I see an unbalanced space at the end. |
My pleasure, thanks for your review |

Example:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
In Pretty format, named tuples are now displayed as Pretty JSON. This closes #65022