Skip to content

Named tuples pretty format#91779

Merged
pamarcos merged 14 commits intoClickHouse:masterfrom
Sasao4o:named-tuples-pretty-format
Dec 17, 2025
Merged

Named tuples pretty format#91779
pamarcos merged 14 commits intoClickHouse:masterfrom
Sasao4o:named-tuples-pretty-format

Conversation

@Sasao4o
Copy link
Copy Markdown
Contributor

@Sasao4o Sasao4o commented Dec 9, 2025

Example:

-- Query
SELECT
    i.InstanceType,
    i.VCpuInfo.1 AS cpu,
    i.InstanceStorageInfo
FROM
(
    SELECT arrayJoin(InstanceTypes) AS i
    FROM instances
)
WHERE i.InstanceStorageSupported
ORDER BY cpu DESC
LIMIT 10


-- Output
┌─i.InstanceType─┬─cpu─┬─i.InstanceStorageInfo───────────────────┐
│ test.large64 │ {                                      ↴│
│                │     │↳  "Disks": [                           ↴│
│                │     │↳   {                                   ↴│
│                │     │↳    "Count": 2,                        ↴│
│                │     │↳    "SizeGB": 1900,                    ↴│
│                │     │↳    "Type": "ssd"                      ↴│
│                │     │↳   }                                   ↴│
│                │     │↳  ],                                   ↴│
│                │     │↳  "EbsOptimizedSupport": "required",   ↴│
│                │     │↳  "EncryptionSupport": "required",     ↴│
│                │     │↳  "TotalSizeGB": 3800                  ↴│
│                │     │↳ }                                      │
│ test.xlarge32 │ {                                      ↴│
│                │     │↳  "Disks": [                           ↴│
│                │     │↳   {                                   ↴│
│                │     │↳    "Count": 4,                        ↴│
│                │     │↳    "SizeGB": 2000,                    ↴│
│                │     │↳    "Type": "ssd"                      ↴│
│                │     │↳   }                                   ↴│
│                │     │↳  ],                                   ↴│
│                │     │↳  "EbsOptimizedSupport": "unsupported",↴│
│                │     │↳  "EncryptionSupport": "unsupported",  ↴│
│                │     │↳  "TotalSizeGB": 8000                  ↴│
│                │     │↳ }                                      │
└────────────────┴─────┴─────────────────────────────────────────┘

Changelog category (leave one):

  • Improvement

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 9, 2025

CLA assistant check
All committers have signed the CLA.

@nihalzp nihalzp added the can be tested Allows running workflows for external contributors label Dec 9, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Dec 9, 2025

Workflow [PR], commit [abbb03d]

Summary:

job_name test_name status info comment
AST fuzzer (amd_tsan) failure
Logical error: Unknown numeric column x of type: A FAIL cidb
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting in Function_minus: the query: FAIL cidb
BuzzHouse (arm_asan) failure
Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected A, found B FAIL cidb, issue
BuzzHouse (amd_ubsan) failure
Logical error: Distributed task iterator is not initialized FAIL cidb, issue
Performance Comparison (amd_release, master_head, 1/6) failure
Select historical data failure
Performance Comparison (amd_release, master_head, 3/6) failure
Select historical data failure
Performance Comparison (amd_release, master_head, 5/6) failure
Select historical data failure
Performance Comparison (amd_release, master_head, 6/6) failure
Select historical data failure

@clickhouse-gh clickhouse-gh bot added the pr-improvement Pull request with some product improvements label Dec 9, 2025
@Sasao4o
Copy link
Copy Markdown
Contributor Author

Sasao4o commented Dec 9, 2025

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

@nikitamikhaylov nikitamikhaylov added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Dec 12, 2025
@pamarcos pamarcos self-assigned this Dec 12, 2025
@pamarcos pamarcos requested a review from Copilot December 12, 2025 11:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_format flag 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
{

Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Remove unnecessary blank line that adds no value to code readability.

Suggested change

Copilot uses AI. Check for mistakes.
if (settings.json.write_named_tuples_as_objects
&& has_explicit_names)
{

Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Remove trailing whitespace that serves no purpose.

Suggested change

Copilot uses AI. Check for mistakes.
@pamarcos
Copy link
Copy Markdown
Member

pamarcos commented Dec 12, 2025

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

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.

@Sasao4o
Copy link
Copy Markdown
Contributor Author

Sasao4o commented Dec 14, 2025

error

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

@pamarcos
Copy link
Copy Markdown
Member

pamarcos commented Dec 15, 2025

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 03727_named_tuples_pretty_format --test-run=10000 -j24 successfully to make sure it worked ok.

Remove trailing whitespaces added by GitHub web UI when solving the merge conflict
@pamarcos pamarcos added this pull request to the merge queue Dec 17, 2025
@pamarcos
Copy link
Copy Markdown
Member

Thanks for working on this, @Sasao4o. Appreciate it 🫶

Merged via the queue into ClickHouse:master with commit 686e6fc Dec 17, 2025
122 of 131 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 17, 2025
@alexey-milovidov
Copy link
Copy Markdown
Member

@pamarcos, On the screenshots and in examples, I see an unbalanced space at the end.

@pamarcos
Copy link
Copy Markdown
Member

pamarcos commented Dec 17, 2025

@pamarcos, On the screenshots and in examples, I see an unbalanced space at the end.

You're absolutely right. I didn't see it because I thought the misalignment was due to the , but there's also an extra whitespace 🙏

This should do it: #92421

@Sasao4o
Copy link
Copy Markdown
Contributor Author

Sasao4o commented Jan 1, 2026

Thanks for working on this, @Sasao4o. Appreciate it 🫶

My pleasure, thanks for your review

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 comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). 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.

Named tuples in Pretty format should be displayed as JSON (or better)

8 participants