diff options
| author | vitalyisaev <[email protected]> | 2023-11-14 09:58:56 +0300 |
|---|---|---|
| committer | vitalyisaev <[email protected]> | 2023-11-14 10:20:20 +0300 |
| commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
| tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/errorCodeToName.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/errorCodeToName.cpp')
| -rw-r--r-- | contrib/clickhouse/src/Functions/errorCodeToName.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/errorCodeToName.cpp b/contrib/clickhouse/src/Functions/errorCodeToName.cpp new file mode 100644 index 00000000000..0025d38c8f2 --- /dev/null +++ b/contrib/clickhouse/src/Functions/errorCodeToName.cpp @@ -0,0 +1,63 @@ +#include <Functions/IFunction.h> +#include <Functions/FunctionFactory.h> +#include <DataTypes/DataTypeLowCardinality.h> +#include <DataTypes/DataTypeString.h> +#include <Columns/ColumnString.h> +#include <Common/ErrorCodes.h> + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int BAD_ARGUMENTS; +} + +/** errorCodeToName() - returns the variable name for the error code. + */ +class FunctionErrorCodeToName : public IFunction +{ +public: + static constexpr auto name = "errorCodeToName"; + static FunctionPtr create(ContextPtr) + { + return std::make_shared<FunctionErrorCodeToName>(); + } + + String getName() const override { return name; } + size_t getNumberOfArguments() const override { return 1; } + bool useDefaultImplementationForConstants() const override { return true; } + bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; } + + DataTypePtr getReturnTypeImpl(const DataTypes & types) const override + { + if (!isNumber(types.at(0))) + throw Exception(ErrorCodes::BAD_ARGUMENTS, "The argument of function {} must have simple numeric type, possibly Nullable", name); + + return std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()); + } + + ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & res_type, size_t input_rows_count) const override + { + const auto & input_column = *arguments[0].column; + auto col_res = res_type->createColumn(); + + for (size_t i = 0; i < input_rows_count; ++i) + { + const Int64 error_code = input_column.getInt(i); + std::string_view error_name = + ErrorCodes::getName(static_cast<ErrorCodes::ErrorCode>(error_code)); + col_res->insertData(error_name.data(), error_name.size()); + } + + return col_res; + } +}; + + +REGISTER_FUNCTION(ErrorCodeToName) +{ + factory.registerFunction<FunctionErrorCodeToName>(); +} + +} |
