CLI: Refactor BoxRenderer, add wrapping support for large values, and add pretty printing / highlighting for nested types, JSON and variant#19721
Merged
Mytherin merged 36 commits intoduckdb:mainfrom Nov 11, 2025
Conversation
…ctually writing to console
…mns by the same proportion
Contributor
|
Mostly curiosity: can / is the JSON rendering applied also for STRUCTs and/or MAPs? Or maybe even ARRAY/LISTs? |
Collaborator
Author
|
Should work with all nested types yes |
github-actions bot
pushed a commit
to duckdb/duckdb-r
that referenced
this pull request
Nov 11, 2025
Refactor BoxRenderer, add wrapping support for large values, and add pretty printing / highlighting for nested types, JSON and variant (duckdb/duckdb#19721) Internal duckdb/duckdb#6523: AsOf Exception Handling (duckdb/duckdb#19703)
github-actions bot
added a commit
to duckdb/duckdb-r
that referenced
this pull request
Nov 11, 2025
Refactor BoxRenderer, add wrapping support for large values, and add pretty printing / highlighting for nested types, JSON and variant (duckdb/duckdb#19721) Internal duckdb/duckdb#6523: AsOf Exception Handling (duckdb/duckdb#19703) Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
Mytherin
added a commit
that referenced
this pull request
Nov 16, 2025
… array entry unless there are complex objects in the array (#19795) Follow-up fix from #19721 When rendering an array that does not contain any complex objects, wrap it on multiple lines instead of adding newlines after every comma, e.g. we render it as this: ``` [1, 2, 3, 4, 5, 6, 7, 8] ``` Instead of this: ``` [ 1, 2, 3, 4, 5, 6, 7, 8 ] ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does a code refactor of the BoxRenderer - cleaning up the code by splitting up the generating of values to render from the actual rendering.
Wrapping
In addition, this PR adds support for wrapping for large values. The way this works is that, when we select fewer rows than the
.maxrows, we allow the result rendering to use multiple lines to display a single row in the query result. Larger values can then be stretched out over multiple lines instead of being truncated, allowing them to be visible. For example:If we exceed the
maxrows, we don't wrap, but still truncate:Similarly, we only allow wrapping until the
maxrowsis reached. If we have a gigantic string we will be able to fit more of it in the result, but still not everything:If we select multiple large strings, we might be able to do some wrapping - but we never exceed
.maxrows. The wrapping is done greedily (i.e. we try to add wrapping for the first value, then the second one, etc). For example:Nested types / JSON / VARIANT
When doing this wrapping for nested types, JSON or variant, we add a "pretty print" step that tries to format the JSON in a nice way - provided it fits on the screen. For example:
file.json
{ "aliceblue": "#f0f8ff", "antiquewhite": "#faebd7", "aqua": "#00ffff", "aquamarine": "#7fffd4", "azure": "#f0ffff", "beige": "#f5f5dc", "bisque": "#ffe4c4", "black": "#000000", "blanchedalmond": "#ffebcd", "blue": "#0000ff", "blueviolet": "#8a2be2", "brown": "#a52a2a", }The formatter will try to adapt to the max width of the terminal, and use a more compact rendering if the terminal width is exceeded by the simpler one. For example:
Just like with wrapping, this formatting is only done if there is space for it, e.g.:
More space can always be made by the user by running e.g.
.maxrows -1.Highlighting
We also add highlighting support for JSON / VARIANT / nested types in results, e.g.: