#pragma once #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int ILLEGAL_COLUMN; extern const int ILLEGAL_TYPE_OF_ARGUMENT; } template class FunctionNumericPredicate : public IFunction { public: static constexpr auto name = Impl::name; static FunctionPtr create(const Context &) { return std::make_shared(); } String getName() const override { return name; } size_t getNumberOfArguments() const override { return 1; } DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { if (!isNativeNumber(arguments.front())) throw Exception{"Argument for function " + getName() + " must be number", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT}; return std::make_shared(); } bool useDefaultImplementationForConstants() const override { return true; } ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override { const auto * in = arguments.front().column.get(); ColumnPtr res; if (!((res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)) || (res = execute(in)))) throw Exception{"Illegal column " + in->getName() + " of first argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN}; return res; } template ColumnPtr execute(const IColumn * in_untyped) const { if (const auto in = checkAndGetColumn>(in_untyped)) { const auto size = in->size(); auto out = ColumnUInt8::create(size); const auto & in_data = in->getData(); auto & out_data = out->getData(); for (const auto i : ext::range(0, size)) out_data[i] = Impl::execute(in_data[i]); return out; } return nullptr; } }; }