Skip to content

Shell: Provide a summary of numbers if we are rendering only a single row #15031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 1, 2024

Conversation

Mytherin
Copy link
Collaborator

@Mytherin Mytherin commented Nov 29, 2024

Many result sets contain only a single row (or single value), for example, when running SELECT COUNT(*) FROM tbl or similar summaries. In those cases, we often receive a single (often big) number. This PR adds support for a human readable rendering of these numbers, e.g.:

Screenshot 2024-11-29 at 16 00 02
Screenshot 2024-11-29 at 16 00 32

This option can be disabled using .large_number_rendering off:

D . large_number_rendering off
D select sum(l_extendedprice), sum(l_discount) from lineitem;
┌──────────────────────┬─────────────────┐
│ sum(l_extendedprice) │ sum(l_discount) │
│    decimal(38,2)     │  decimal(38,2)  │
├──────────────────────┼─────────────────┤
│     2293813156773.362999373.24 │
└──────────────────────┴─────────────────┘

In addition, this can be applied to all numeric values using .large_number_rendering all

Screenshot 2024-11-30 at 13 35 41

@Maxxen
Copy link
Member

Maxxen commented Nov 29, 2024

Love it!

@carlopi
Copy link
Contributor

carlopi commented Nov 29, 2024

I love both of you, but ... I don't get it, I don't like (at all) the fact that this is not composable / special cased.

Apart from taste, I think one connected feedback is that it would be cool to have a way to persist this setting across sessions directly FROM the cli. Either a modifier on a given command, say .persist '.timer on', or like: .edit_rc that goes into editing ~/.duckdbrc (or whatever file we load by default).

Then it becomes simpler to add stuff, while making it easy for people to remember setting.

@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 29, 2024 22:29
@Mytherin Mytherin marked this pull request as ready for review November 29, 2024 22:29
@Mytherin
Copy link
Collaborator Author

Mytherin commented Nov 29, 2024

It's a contextual rendering that provides an easier way to see what a result means. The point of duckbox is to provide human-readable snapshots of result sets. That's also why we e.g. truncate rows/columns so that they fit the terminal window.

I guess we could optionally enable it for multiple rows (which is what I assume you mean with "it is not composable"?) - but that gets very busy very quickly since it doubles the rendering size of the result set. I think the single-row is a good compromise, since single-row queries are very common (especially for COUNT(*) which is the main purpose of this rendering).

@Mytherin
Copy link
Collaborator Author

Maybe a good compromise is to leave it out by default when stdout is not a terminal?

@carlopi
Copy link
Contributor

carlopi commented Nov 29, 2024

Thanks for the deeper explanation! I sounded more certain than I am, and it's right that duckbox is not used by tools (that can do -md) / what not that is easier to parse, I guess trust your (and Max) judgment, we can always have it in first and experiment with it, we are not releasing tomorrow.

@Mytherin
Copy link
Collaborator Author

Thinking about this a bit more, maybe it would be nice to offer this at three levels:

  • off - all numbers are printed using regular formatting
  • footer - what this PR implements, for single row results large numbers are augmented with the readable format
  • all - replace all large numbers with readable format

@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 30, 2024 12:33
@Mytherin Mytherin marked this pull request as ready for review November 30, 2024 12:35
@duckdb-draftbot duckdb-draftbot marked this pull request as draft November 30, 2024 12:43
@Mytherin Mytherin marked this pull request as ready for review November 30, 2024 12:43
@Mytherin Mytherin merged commit 24d5a32 into duckdb:main Dec 1, 2024
42 checks passed
@Mytherin Mytherin deleted the numbersummary branch December 8, 2024 06:51
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request Dec 27, 2024
Shell: Provide a summary of numbers if we are rendering only a single row (duckdb/duckdb#15031)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request Dec 27, 2024
Shell: Provide a summary of numbers if we are rendering only a single row (duckdb/duckdb#15031)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request Dec 27, 2024
Shell: Provide a summary of numbers if we are rendering only a single row (duckdb/duckdb#15031)
github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Dec 28, 2024
Shell: Provide a summary of numbers if we are rendering only a single row (duckdb/duckdb#15031)
github-actions bot added a commit to duckdb/duckdb-r that referenced this pull request Dec 28, 2024
Shell: Provide a summary of numbers if we are rendering only a single row (duckdb/duckdb#15031)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Documentation Use for issues or PRs that require changes in the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants