@@ -902,19 +902,11 @@ void BoxRenderer::RenderValues(const list<ColumnDataCollection> &collections, co
902902 }
903903}
904904
905- void BoxRenderer::RenderRowCount (string row_count_str, string shown_str, const string &column_count_str,
906- const vector<idx_t > &boundaries, bool has_hidden_rows, bool has_hidden_columns,
907- idx_t total_length, idx_t row_count, idx_t column_count, idx_t minimum_row_length,
908- BaseResultRenderer &ss) {
909- // check if we can merge the row_count_str and the shown_str
910- bool display_shown_separately = has_hidden_rows;
911- if (has_hidden_rows && total_length >= row_count_str.size () + shown_str.size () + 5 ) {
912- // we can!
913- row_count_str += " " + shown_str;
914- shown_str = string ();
915- display_shown_separately = false ;
916- minimum_row_length = row_count_str.size () + 4 ;
917- }
905+ void BoxRenderer::RenderRowCount (string &row_count_str, string &readable_rows_str, string &shown_str,
906+ const string &column_count_str, const vector<idx_t > &boundaries, bool has_hidden_rows,
907+ bool has_hidden_columns, idx_t total_length, idx_t row_count, idx_t column_count,
908+ idx_t minimum_row_length, BaseResultRenderer &ss) {
909+ // check if we can merge the row_count_str, readable_rows_str and the shown_str
918910 auto minimum_length = row_count_str.size () + column_count_str.size () + 6 ;
919911 bool render_rows_and_columns = total_length >= minimum_length &&
920912 ((has_hidden_columns && row_count > 0 ) || (row_count >= 10 && column_count > 1 ));
@@ -941,23 +933,75 @@ void BoxRenderer::RenderRowCount(string row_count_str, string shown_str, const s
941933 if (!render_anything) {
942934 return ;
943935 }
936+ idx_t padding = total_length - row_count_str.size () - 4 ;
937+ if (render_rows_and_columns) {
938+ padding -= column_count_str.size ();
939+ }
940+ string extra_render_str;
941+ // do we have to space to render the minimum_row_length and the shown string on the same row?
942+ idx_t shown_size = readable_rows_str.size () + shown_str.size () + (readable_rows_str.empty () ? 3 : 5 );
943+ if (has_hidden_rows && padding >= shown_size) {
944+ // we have space - render it here
945+ extra_render_str = " (" ;
946+ if (!readable_rows_str.empty ()) {
947+ extra_render_str += readable_rows_str + " , " ;
948+ }
949+ extra_render_str += shown_str;
950+ extra_render_str += " )" ;
951+ D_ASSERT (extra_render_str.size () == shown_size);
952+ padding -= shown_size;
953+ readable_rows_str = string ();
954+ shown_str = string ();
955+ }
944956
957+ ss << config.VERTICAL ;
958+ ss << " " ;
945959 if (render_rows_and_columns) {
946- ss << config.VERTICAL ;
947- ss << " " ;
948960 ss.Render (ResultRenderType::FOOTER, row_count_str);
949- ss << string (total_length - row_count_str.size () - column_count_str.size () - 4 , ' ' );
961+ if (!extra_render_str.empty ()) {
962+ ss.Render (ResultRenderType::NULL_VALUE, extra_render_str);
963+ }
964+ ss << string (padding, ' ' );
950965 ss.Render (ResultRenderType::FOOTER, column_count_str);
951- ss << " " ;
952- ss << config.VERTICAL ;
953- ss << ' \n ' ;
954966 } else if (render_rows) {
955- RenderValue (ss, row_count_str, total_length - 4 , ResultRenderType::FOOTER);
956- ss << config.VERTICAL ;
957- ss << ' \n ' ;
958-
959- if (display_shown_separately) {
960- RenderValue (ss, shown_str, total_length - 4 , ResultRenderType::FOOTER);
967+ idx_t lpadding = padding / 2 ;
968+ idx_t rpadding = padding - lpadding;
969+ ss << string (lpadding, ' ' );
970+ ss.Render (ResultRenderType::FOOTER, row_count_str);
971+ if (!extra_render_str.empty ()) {
972+ ss.Render (ResultRenderType::NULL_VALUE, extra_render_str);
973+ }
974+ ss << string (rpadding, ' ' );
975+ }
976+ ss << " " ;
977+ ss << config.VERTICAL ;
978+ ss << ' \n ' ;
979+ if (!readable_rows_str.empty () || !shown_str.empty ()) {
980+ // we still need to render the readable rows/shown strings
981+ // check if we can merge the two onto one row
982+ idx_t combined_shown_length = readable_rows_str.size () + shown_str.size () + 4 ;
983+ if (combined_shown_length <= total_length) {
984+ // we can! merge them
985+ ss << config.VERTICAL ;
986+ ss << " " ;
987+ ss.Render (ResultRenderType::NULL_VALUE, readable_rows_str);
988+ ss << string (total_length - combined_shown_length, ' ' );
989+ ss.Render (ResultRenderType::NULL_VALUE, shown_str);
990+ ss << " " ;
991+ ss << config.VERTICAL ;
992+ ss << ' \n ' ;
993+ readable_rows_str = string ();
994+ shown_str = string ();
995+ }
996+ ValueRenderAlignment alignment =
997+ render_rows_and_columns ? ValueRenderAlignment::LEFT : ValueRenderAlignment::MIDDLE;
998+ if (!readable_rows_str.empty ()) {
999+ RenderValue (ss, " (" + readable_rows_str + " )" , total_length - 4 , ResultRenderType::NULL_VALUE, alignment);
1000+ ss << config.VERTICAL ;
1001+ ss << ' \n ' ;
1002+ }
1003+ if (!shown_str.empty ()) {
1004+ RenderValue (ss, " (" + shown_str + " )" , total_length - 4 , ResultRenderType::NULL_VALUE, alignment);
9611005 ss << config.VERTICAL ;
9621006 ss << ' \n ' ;
9631007 }
@@ -1011,16 +1055,23 @@ void BoxRenderer::Render(ClientContext &context, const vector<string> &names, co
10111055 if (has_limited_rows) {
10121056 row_count_str = " ? rows" ;
10131057 }
1058+ string readable_rows_str;
1059+ if (config.large_number_rendering == LargeNumberRendering::FOOTER && !has_limited_rows) {
1060+ readable_rows_str = TryFormatLargeNumber (to_string (row_count));
1061+ if (!readable_rows_str.empty ()) {
1062+ readable_rows_str += " rows" ;
1063+ }
1064+ }
10141065 string shown_str;
10151066 bool has_hidden_rows = top_rows < row_count;
10161067 if (has_hidden_rows) {
1017- shown_str = " (" ;
10181068 if (has_limited_rows) {
10191069 shown_str += " >" + FormatNumber (to_string (config.limit - 1 )) + " rows, " ;
10201070 }
1021- shown_str += FormatNumber (to_string (top_rows + bottom_rows)) + " shown) " ;
1071+ shown_str += FormatNumber (to_string (top_rows + bottom_rows)) + " shown" ;
10221072 }
1023- auto minimum_row_length = MaxValue<idx_t >(row_count_str.size (), shown_str.size ()) + 4 ;
1073+ auto minimum_row_length =
1074+ MaxValue<idx_t >(MaxValue<idx_t >(row_count_str.size (), shown_str.size () + 2 ), readable_rows_str.size () + 2 ) + 4 ;
10241075
10251076 // fetch the top and bottom render collections from the result
10261077 auto collections = FetchRenderCollections (context, result, top_rows, bottom_rows);
@@ -1073,7 +1124,7 @@ void BoxRenderer::Render(ClientContext &context, const vector<string> &names, co
10731124 if (config.render_mode == RenderMode::COLUMNS) {
10741125 if (has_hidden_columns) {
10751126 has_hidden_rows = true ;
1076- shown_str = " ( " + to_string (column_count - 3 ) + " shown) " ;
1127+ shown_str = to_string (column_count - 3 ) + " shown" ;
10771128 } else {
10781129 shown_str = string ();
10791130 }
@@ -1084,7 +1135,7 @@ void BoxRenderer::Render(ClientContext &context, const vector<string> &names, co
10841135 }
10851136 }
10861137
1087- RenderRowCount (std::move ( row_count_str), std::move ( shown_str) , column_count_str, boundaries, has_hidden_rows,
1138+ RenderRowCount (row_count_str, readable_rows_str, shown_str, column_count_str, boundaries, has_hidden_rows,
10881139 has_hidden_columns, total_length, row_count, column_count, minimum_row_length, ss);
10891140}
10901141
0 commit comments