From 4ff528140a3ecc121a980371a9c96c4cf1c61caf Mon Sep 17 00:00:00 2001 From: Alexey Arno Date: Wed, 6 Jul 2016 13:36:58 +0300 Subject: [PATCH] dbms: Server: Feature development. [#METR-19266] --- .../DB/Functions/FunctionsMiscellaneous.h | 5 +++ .../DataStreams/PrettyBlockOutputStream.cpp | 32 +++++++++++++++---- dbms/src/Functions/FunctionsMiscellaneous.cpp | 3 ++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/dbms/include/DB/Functions/FunctionsMiscellaneous.h b/dbms/include/DB/Functions/FunctionsMiscellaneous.h index a1c200338b6..696cbe38342 100644 --- a/dbms/include/DB/Functions/FunctionsMiscellaneous.h +++ b/dbms/include/DB/Functions/FunctionsMiscellaneous.h @@ -171,6 +171,11 @@ public: return name; } + bool hasSpecialSupportForNullValues() const override + { + return true; + } + /// Получить тип результата по типам аргументов. Если функция неприменима для данных аргументов - кинуть исключение. DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { diff --git a/dbms/src/DataStreams/PrettyBlockOutputStream.cpp b/dbms/src/DataStreams/PrettyBlockOutputStream.cpp index e5bcc386fe2..645995c9ee7 100644 --- a/dbms/src/DataStreams/PrettyBlockOutputStream.cpp +++ b/dbms/src/DataStreams/PrettyBlockOutputStream.cpp @@ -2,8 +2,9 @@ #include #include - #include +#include +#include namespace DB @@ -46,20 +47,39 @@ void PrettyBlockOutputStream::calculateWidths(Block & block, Widths_t & max_widt column.column = block.getByPosition(i + columns).column; - if (const ColumnUInt64 * col = typeid_cast(&*column.column)) + IColumn * observed_col; + if (column.column.get()->isNullable()) + { + ColumnNullable & nullable_col = static_cast(*(column.column.get())); + observed_col = nullable_col.getNestedColumn().get(); + } + else + observed_col = column.column.get(); + + if (const ColumnUInt64 * col = typeid_cast(observed_col)) { const ColumnUInt64::Container_t & res = col->getData(); for (size_t j = 0; j < rows; ++j) - if (res[j] > max_widths[i]) - max_widths[i] = res[j]; + { + Field f = (*(block.getByPosition(columns + i).column))[j]; + + size_t cur_width; + if (f.isNull()) + cur_width = NullSymbol::Escaped::length; + else + cur_width = res[j]; + + if (cur_width > max_widths[i]) + max_widths[i] = cur_width; + } } - else if (const ColumnConstUInt64 * col = typeid_cast(&*column.column)) + else if (const ColumnConstUInt64 * col = typeid_cast(observed_col)) { UInt64 res = col->getData(); max_widths[i] = res; } else - throw Exception("Illegal column " + column.column->getName() + throw Exception("Illegal column " + observed_col->getName() + " of result of function " + visible_width_func.getName(), ErrorCodes::ILLEGAL_COLUMN); diff --git a/dbms/src/Functions/FunctionsMiscellaneous.cpp b/dbms/src/Functions/FunctionsMiscellaneous.cpp index 43c739ac151..da1855ca70d 100644 --- a/dbms/src/Functions/FunctionsMiscellaneous.cpp +++ b/dbms/src/Functions/FunctionsMiscellaneous.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -368,6 +369,8 @@ void FunctionVisibleWidth::executeImpl(Block & block, const ColumnNumbers & argu */ block.getByPosition(result).column = std::make_shared(rows, 10); } + else if (typeid_cast(&*column) != nullptr) + block.getByPosition(result).column = std::make_shared(rows, strlen_constexpr("NULL")); else throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName() + " of argument of function " + getName(),