mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 18:12:02 +00:00
Print number tips in case of LowCardinality and Nullable
This commit is contained in:
parent
a2d9a32652
commit
cde1b82ebd
@ -22,6 +22,7 @@ namespace ErrorCodes
|
||||
extern const int LOGICAL_ERROR;
|
||||
extern const int ILLEGAL_COLUMN;
|
||||
extern const int NOT_IMPLEMENTED;
|
||||
extern const int BAD_ARGUMENTS;
|
||||
}
|
||||
|
||||
|
||||
@ -116,6 +117,38 @@ void ColumnNullable::get(size_t n, Field & res) const
|
||||
getNestedColumn().get(n, res);
|
||||
}
|
||||
|
||||
Float64 ColumnNullable::getFloat64(size_t n) const
|
||||
{
|
||||
if (isNullAt(n))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "The value of {} at {} is NULL while calling method getFloat64", getName(), n);
|
||||
else
|
||||
return getNestedColumn().getFloat64(n);
|
||||
}
|
||||
|
||||
Float32 ColumnNullable::getFloat32(size_t n) const
|
||||
{
|
||||
if (isNullAt(n))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "The value of {} at {} is NULL while calling method getFloat32", getName(), n);
|
||||
else
|
||||
return getNestedColumn().getFloat32(n);
|
||||
}
|
||||
|
||||
UInt64 ColumnNullable::getUInt(size_t n) const
|
||||
{
|
||||
if (isNullAt(n))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "The value of {} at {} is NULL while calling method getUInt", getName(), n);
|
||||
else
|
||||
return getNestedColumn().getUInt(n);
|
||||
}
|
||||
|
||||
Int64 ColumnNullable::getInt(size_t n) const
|
||||
{
|
||||
if (isNullAt(n))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "The value of {} at {} is NULL while calling method getInt", getName(), n);
|
||||
else
|
||||
return getNestedColumn().getInt(n);
|
||||
}
|
||||
|
||||
void ColumnNullable::insertData(const char * pos, size_t length)
|
||||
{
|
||||
if (pos == nullptr)
|
||||
|
@ -57,6 +57,10 @@ public:
|
||||
void get(size_t n, Field & res) const override;
|
||||
bool getBool(size_t n) const override { return isNullAt(n) ? false : nested_column->getBool(n); }
|
||||
UInt64 get64(size_t n) const override { return nested_column->get64(n); }
|
||||
Float64 getFloat64(size_t n) const override;
|
||||
Float32 getFloat32(size_t n) const override;
|
||||
UInt64 getUInt(size_t n) const override;
|
||||
Int64 getInt(size_t n) const override;
|
||||
bool isDefaultAt(size_t n) const override { return isNullAt(n); }
|
||||
StringRef getDataAt(size_t) const override;
|
||||
/// Will insert null value if pos=nullptr
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <Common/UTF8Helpers.h>
|
||||
#include <Common/PODArray.h>
|
||||
#include <Common/formatReadable.h>
|
||||
#include <DataTypes/DataTypeLowCardinality.h>
|
||||
#include <DataTypes/DataTypeNullable.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -16,7 +18,14 @@ 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();
|
||||
/// Decide whether we should print a tip near the single number value in the result.
|
||||
if (header_.getColumns().size() == 1)
|
||||
{
|
||||
/// Check if it is a numeric type, possible wrapped by Nullable or LowCardinality.
|
||||
DataTypePtr type = removeNullable(recursiveRemoveLowCardinality(header_.getDataTypes().at(0)));
|
||||
if (isNumber(type))
|
||||
readable_number_tip = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -497,6 +506,9 @@ void PrettyBlockOutputFormat::writeReadableNumberTip(const Chunk & chunk)
|
||||
if (!is_single_number)
|
||||
return;
|
||||
|
||||
if (columns[0]->isNullAt(0))
|
||||
return;
|
||||
|
||||
auto value = columns[0]->getFloat64(0);
|
||||
auto threshold = format_settings.pretty.output_format_pretty_single_large_number_tip_threshold;
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
┌─────────x─┐
|
||||
1. │ 123456789 │ -- 123.46 million
|
||||
└───────────┘
|
||||
┌─────────x─┐
|
||||
1. │ 123456789 │ -- 123.46 million
|
||||
└───────────┘
|
||||
┌─────────x─┐
|
||||
1. │ 123456789 │ -- 123.46 million
|
||||
└───────────┘
|
||||
┌─────────x─┐
|
||||
1. │ 123456789 │ -- 123.46 million
|
||||
└───────────┘
|
||||
┌─────────x─┐
|
||||
1. │ 123456789 │ -- 123.46 million
|
||||
└───────────┘
|
||||
Nullable(UInt64), Nullable(size = 10, UInt64(size = 10), UInt8(size = 10))
|
||||
┏━━━━━━━━━━━━┓
|
||||
┃ x ┃
|
||||
┡━━━━━━━━━━━━┩
|
||||
1. │ 1111111101 │ -- 1.11 billion
|
||||
└────────────┘
|
||||
┏━━━━━━━━━━━┓
|
||||
┃ x ┃
|
||||
┡━━━━━━━━━━━┩
|
||||
1. │ 123456789 │ -- 123.46 million
|
||||
└───────────┘
|
||||
x
|
||||
|
||||
1. ᴺᵁᴸᴸ
|
||||
UInt64, Sparse(size = 10, UInt64(size = 6), UInt64(size = 5))
|
||||
┏━━━━━━━━━━━━┓
|
||||
┃ x ┃
|
||||
┡━━━━━━━━━━━━┩
|
||||
1. │ 1111111101 │ -- 1.11 billion
|
||||
└────────────┘
|
||||
┏━━━┓
|
||||
┃ x ┃
|
||||
┡━━━┩
|
||||
1. │ 0 │
|
||||
└───┘
|
||||
x
|
||||
|
||||
1. 0
|
24
tests/queries/0_stateless/03156_nullable_number_tips.sql
Normal file
24
tests/queries/0_stateless/03156_nullable_number_tips.sql
Normal file
@ -0,0 +1,24 @@
|
||||
SELECT 123456789 AS x FORMAT PrettyCompact;
|
||||
SELECT toNullable(123456789) AS x FORMAT PrettyCompact;
|
||||
SELECT toLowCardinality(toNullable(123456789)) AS x FORMAT PrettyCompact;
|
||||
SELECT toNullable(toLowCardinality(123456789)) AS x FORMAT PrettyCompact;
|
||||
SELECT toLowCardinality(123456789) AS x FORMAT PrettyCompact;
|
||||
|
||||
CREATE TEMPORARY TABLE test (x Nullable(UInt64), PRIMARY KEY ()) ENGINE = MergeTree SETTINGS ratio_of_defaults_for_sparse_serialization = 0;
|
||||
INSERT INTO test SELECT number % 2 ? number * 123456789 : NULL FROM numbers(10);
|
||||
|
||||
SELECT DISTINCT dumpColumnStructure(*) FROM test;
|
||||
|
||||
SELECT * FROM test ORDER BY ALL DESC NULLS LAST LIMIT 1 FORMAT PRETTY;
|
||||
SELECT * FROM test ORDER BY ALL ASC NULLS LAST LIMIT 1 FORMAT PRETTY;
|
||||
SELECT * FROM test ORDER BY ALL ASC NULLS FIRST LIMIT 1 FORMAT PrettySpace;
|
||||
|
||||
DROP TEMPORARY TABLE test;
|
||||
CREATE TEMPORARY TABLE test (x UInt64, PRIMARY KEY ()) ENGINE = MergeTree SETTINGS ratio_of_defaults_for_sparse_serialization = 0;
|
||||
INSERT INTO test SELECT number % 2 ? number * 123456789 : NULL FROM numbers(10);
|
||||
|
||||
SELECT DISTINCT dumpColumnStructure(*) FROM test;
|
||||
|
||||
SELECT * FROM test ORDER BY ALL DESC NULLS LAST LIMIT 1 FORMAT PRETTY;
|
||||
SELECT * FROM test ORDER BY ALL ASC NULLS LAST LIMIT 1 FORMAT PRETTY;
|
||||
SELECT * FROM test ORDER BY ALL ASC NULLS FIRST LIMIT 1 FORMAT PrettySpace;
|
Loading…
Reference in New Issue
Block a user