Merge branch 'fix-bad-numbers-pretty-printing' into dont-cut-single-value

This commit is contained in:
Alexey Milovidov 2024-03-23 04:57:08 +01:00
commit fa3c9dc664
3 changed files with 48 additions and 4 deletions

View File

@ -13,8 +13,6 @@ namespace DB
}
}
// I wanted to make this ALWAYS_INLINE to prevent flappy performance tests,
// but GCC complains it may not be inlined.
static void formatReadable(double size, DB::WriteBuffer & out,
int precision, const char ** units, size_t units_size, double delimiter)
{
@ -25,7 +23,12 @@ static void formatReadable(double size, DB::WriteBuffer & out,
DB::DoubleConverter<false>::BufferType buffer;
double_conversion::StringBuilder builder{buffer, sizeof(buffer)};
const auto result = DB::DoubleConverter<false>::instance().ToFixed(size, precision, &builder);
const auto & converter = DB::DoubleConverter<false>::instance();
auto result = converter.ToFixed(size, precision, &builder);
if (!result)
result = converter.ToShortest(size, &builder);
if (!result)
throw DB::Exception(DB::ErrorCodes::CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER, "Cannot print float or double number");
@ -65,7 +68,11 @@ std::string formatReadableSizeWithDecimalSuffix(double value, int precision)
void formatReadableQuantity(double value, DB::WriteBuffer & out, int precision)
{
const char * units[] = {"", " thousand", " million", " billion", " trillion", " quadrillion"};
const char * units[] = {"", " thousand", " million", " billion", " trillion", " quadrillion",
" quintillion", " sextillion", " septillion", " octillion", " nonillion", " decillion",
" undecillion", " duodecillion", " tredecillion", " quattuordecillion", " quindecillion",
" sexdecillion", " septendecillion", " octodecillion", " novemdecillion", " vigintillion"};
formatReadable(value, out, precision, units, sizeof(units) / sizeof(units[0]), 1000);
}

View File

@ -0,0 +1,30 @@
┏━━━━━━━━━━━━━┓
┃ 1230000000. ┃
┡━━━━━━━━━━━━━┩
│ 1230000000 │ -- 1.23 billion
└─────────────┘
┏━━━━━━━━━━━━━━┓
┃ -1230000000. ┃
┡━━━━━━━━━━━━━━┩
│ -1230000000 │ -- -1.23 billion
└──────────────┘
┏━━━━━┓
┃ inf ┃
┡━━━━━┩
│ inf │
└─────┘
┏━━━━━━┓
┃ -inf ┃
┡━━━━━━┩
│ -inf │
└──────┘
┏━━━━━┓
┃ nan ┃
┡━━━━━┩
│ nan │
└─────┘
┏━━━━━━━┓
┃ 1e111 ┃
┡━━━━━━━┩
│ 1e111 │ -- 1000000000000000206105119874289560746212057939968.00 vigintillion
└───────┘

View File

@ -0,0 +1,7 @@
SET output_format_pretty_row_numbers = 0;
SELECT 1.23e9 FORMAT Pretty;
SELECT -1.23e9 FORMAT Pretty;
SELECT inf FORMAT Pretty;
SELECT -inf FORMAT Pretty;
SELECT nan FORMAT Pretty;
SELECT 1e111 FORMAT Pretty;