diff options
| author | AlexSm <[email protected]> | 2024-01-04 15:09:05 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-04 15:09:05 +0100 |
| commit | dab291146f6cd7d35684e3a1150e5bb1c412982c (patch) | |
| tree | 36ef35f6cacb6432845a4a33f940c95871036b32 /contrib/clickhouse/src/Functions/FunctionChar.cpp | |
| parent | 63660ad5e7512029fd0218e7a636580695a24e1f (diff) | |
Library import 5, delete go dependencies (#832)
* Library import 5, delete go dependencies
* Fix yt client
Diffstat (limited to 'contrib/clickhouse/src/Functions/FunctionChar.cpp')
| -rw-r--r-- | contrib/clickhouse/src/Functions/FunctionChar.cpp | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/contrib/clickhouse/src/Functions/FunctionChar.cpp b/contrib/clickhouse/src/Functions/FunctionChar.cpp deleted file mode 100644 index 055eb08f0c7..00000000000 --- a/contrib/clickhouse/src/Functions/FunctionChar.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include <Columns/ColumnString.h> -#include <Columns/ColumnsNumber.h> -#include <DataTypes/DataTypeString.h> -#include <Functions/FunctionHelpers.h> -#include <Functions/FunctionFactory.h> -#include <Functions/IFunction.h> -#include <Interpreters/Context_fwd.h> -#include <Interpreters/castColumn.h> -#include <IO/WriteHelpers.h> - -namespace DB -{ - -namespace ErrorCodes -{ - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - -class FunctionChar : public IFunction -{ -public: - static constexpr auto name = "char"; - static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionChar>(); } - - String getName() const override - { - return name; - } - - bool isVariadic() const override { return true; } - bool isInjective(const ColumnsWithTypeAndName &) const override { return true; } - bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; } - size_t getNumberOfArguments() const override { return 0; } - - DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override - { - if (arguments.empty()) - throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Number of arguments for function {} can't be {}, should be at least 1", - getName(), arguments.size()); - - for (const auto & arg : arguments) - { - WhichDataType which(arg); - if (!(which.isInt() || which.isUInt() || which.isFloat())) - throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument of function {}, must be Int, UInt or Float number", - arg->getName(), getName()); - } - return std::make_shared<DataTypeString>(); - } - - bool useDefaultImplementationForConstants() const override { return true; } - - ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override - { - auto col_str = ColumnString::create(); - ColumnString::Chars & out_vec = col_str->getChars(); - ColumnString::Offsets & out_offsets = col_str->getOffsets(); - - const auto size_per_row = arguments.size() + 1; - out_vec.resize(size_per_row * input_rows_count); - out_offsets.resize(input_rows_count); - - for (size_t row = 0; row < input_rows_count; ++row) - { - out_offsets[row] = size_per_row + out_offsets[row - 1]; - out_vec[row * size_per_row + size_per_row - 1] = '\0'; - } - - Columns columns_holder(arguments.size()); - for (size_t idx = 0; idx < arguments.size(); ++idx) - { - //partial const column - columns_holder[idx] = arguments[idx].column->convertToFullColumnIfConst(); - const IColumn * column = columns_holder[idx].get(); - - if (!(executeNumber<UInt8>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<UInt16>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<UInt32>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<UInt64>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<Int8>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<Int16>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<Int32>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<Int64>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<Float32>(*column, out_vec, idx, input_rows_count, size_per_row) - || executeNumber<Float64>(*column, out_vec, idx, input_rows_count, size_per_row))) - { - throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of first argument of function {}", - arguments[idx].column->getName(), getName()); - } - } - - return col_str; - } - -private: - template <typename T> - bool executeNumber(const IColumn & src_data, ColumnString::Chars & out_vec, const size_t & column_idx, const size_t & rows, const size_t & size_per_row) const - { - const ColumnVector<T> * src_data_concrete = checkAndGetColumn<ColumnVector<T>>(&src_data); - - if (!src_data_concrete) - { - return false; - } - - for (size_t row = 0; row < rows; ++row) - { - out_vec[row * size_per_row + column_idx] = static_cast<char>(src_data_concrete->getInt(row)); - } - return true; - } -}; - -REGISTER_FUNCTION(Char) -{ - factory.registerFunction<FunctionChar>({}, FunctionFactory::CaseInsensitive); -} - -} |
