diff --git a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp index 4c20a852117..c5db8f2e30a 100644 --- a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp +++ b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp @@ -16,6 +16,7 @@ PrettyBlockOutputFormat::PrettyBlockOutputFormat( WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_, bool mono_block_, bool color_) : IOutputFormat(header_, out_), format_settings(format_settings_), serializations(header_.getSerializations()), color(color_), mono_block(mono_block_) { + readable_number_tip = header_.getColumns().size() == 1 && WhichDataType(header_.getDataTypes()[0]->getTypeId()).isNumber(); } @@ -415,7 +416,7 @@ void PrettyBlockOutputFormat::writeSuffix() void PrettyBlockOutputFormat::writeReadableNumberTip(const Chunk & chunk) { auto columns = chunk.getColumns(); - auto is_single_number = chunk.getNumRows() == 1 && chunk.getNumColumns() == 1 && WhichDataType(columns[0]->getDataType()).isNumber(); + auto is_single_number = readable_number_tip && chunk.getNumRows() == 1 && chunk.getNumColumns() == 1; if (!is_single_number) return; auto value = columns[0]->getFloat64(0); diff --git a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h index 680d39d8700..071bfa92e35 100644 --- a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h +++ b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h @@ -58,6 +58,7 @@ protected: bool color; private: + bool readable_number_tip = false; bool mono_block; /// For mono_block == true only Chunk mono_chunk; diff --git a/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.reference b/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.reference index 482ad58862c..496e0337209 100644 --- a/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.reference +++ b/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.reference @@ -278,3 +278,83 @@ 1000000000 1000000000 +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date32') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└──────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date32') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└──────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date32') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└──────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29', 'Date32') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 │ +└──────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29 00:00:00', 'DateTime') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00 │ +└─────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29 00:00:00', 'DateTime') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00 │ +└─────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29 00:00:00', 'DateTime') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00 │ +└─────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST('2024-02-29 00:00:00', 'DateTime') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00 │ +└─────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST(CAST('2024-02-29 00:00:00', 'DateTime'), 'DateTime64') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00.000 │ +└─────────────────────────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST(CAST('2024-02-29 00:00:00', 'DateTime'), 'DateTime64') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00.000 │ +└─────────────────────────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST(CAST('2024-02-29 00:00:00', 'DateTime'), 'DateTime64') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00.000 │ +└─────────────────────────────────────────────────────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ CAST(CAST('2024-02-29 00:00:00', 'DateTime'), 'DateTime64') ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 2024-02-29 00:00:00.000 │ +└─────────────────────────────────────────────────────────────┘ diff --git a/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.sql b/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.sql index 6bbe9064c42..5dc69488cea 100644 --- a/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.sql +++ b/tests/queries/0_stateless/02998_pretty_format_print_readable_number_on_single_value.sql @@ -77,3 +77,20 @@ SELECT 1_000_000_000 as a FROM system.numbers LIMIT 2 FORMAT PrettySpaceNoEscape SELECT 1_000_000_000 as a FROM system.numbers LIMIT 2 FORMAT PrettySpaceMonoBlock; SELECT 1_000_000_000 as a FROM system.numbers LIMIT 2 FORMAT PrettySpaceNoEscapesMonoBlock; +SET output_format_pretty_single_large_number_tip_threshold=1; +SELECT '2024-02-29'::Date FORMAT Pretty; +SELECT '2024-02-29'::Date FORMAT PrettyNoEscapes; +SELECT '2024-02-29'::Date FORMAT PrettyMonoBlock; +SELECT '2024-02-29'::Date FORMAT PrettyNoEscapesMonoBlock; +SELECT '2024-02-29'::Date32 FORMAT Pretty; +SELECT '2024-02-29'::Date32 FORMAT PrettyNoEscapes; +SELECT '2024-02-29'::Date32 FORMAT PrettyMonoBlock; +SELECT '2024-02-29'::Date32 FORMAT PrettyNoEscapesMonoBlock; +SELECT '2024-02-29 00:00:00'::DateTime FORMAT Pretty; +SELECT '2024-02-29 00:00:00'::DateTime FORMAT PrettyNoEscapes; +SELECT '2024-02-29 00:00:00'::DateTime FORMAT PrettyMonoBlock; +SELECT '2024-02-29 00:00:00'::DateTime FORMAT PrettyNoEscapesMonoBlock; +SELECT '2024-02-29 00:00:00'::DateTime::DateTime64 FORMAT Pretty; +SELECT '2024-02-29 00:00:00'::DateTime::DateTime64 FORMAT PrettyNoEscapes; +SELECT '2024-02-29 00:00:00'::DateTime::DateTime64 FORMAT PrettyMonoBlock; +SELECT '2024-02-29 00:00:00'::DateTime::DateTime64 FORMAT PrettyNoEscapesMonoBlock;