diff --git a/src/Functions/FunctionDateOrDateTimeAddInterval.h b/src/Functions/FunctionDateOrDateTimeAddInterval.h index fbfc9e9bc1f..c0c000452fc 100644 --- a/src/Functions/FunctionDateOrDateTimeAddInterval.h +++ b/src/Functions/FunctionDateOrDateTimeAddInterval.h @@ -611,7 +611,7 @@ public: ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); if (!isNativeNumber(arguments[1].type)) - throw Exception("Second argument for function " + getName() + " (delta) must be number", + throw Exception("Second argument for function " + getName() + " (delta) must be a number", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); if (arguments.size() == 2) @@ -627,7 +627,7 @@ public: { throw Exception( "Function " + getName() + " supports 2 or 3 arguments. The 1st argument " - "must be of type Date or DateTime. The 2nd argument must be number. " + "must be of type Date or DateTime. The 2nd argument must be a number. " "The 3rd argument (optional) must be " "a constant string with timezone name. The timezone argument is allowed " "only when the 1st argument has the type DateTime", diff --git a/src/Functions/FunctionNumericPredicate.h b/src/Functions/FunctionNumericPredicate.h index 9d98f0c929d..496564b0b55 100644 --- a/src/Functions/FunctionNumericPredicate.h +++ b/src/Functions/FunctionNumericPredicate.h @@ -46,7 +46,7 @@ public: 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}; + throw Exception{"Argument for function " + getName() + " must be a number", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT}; return std::make_shared(); } diff --git a/src/Functions/makeDate.cpp b/src/Functions/makeDate.cpp index 5b04ed05a3c..34c681736f0 100644 --- a/src/Functions/makeDate.cpp +++ b/src/Functions/makeDate.cpp @@ -62,7 +62,7 @@ protected: DataTypePtr argument_type = arguments[i].type; if (!isNumber(argument_type)) throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Argument '{}' for function {} must be number", std::string(argument_names[i]), getName()); + "Argument '{}' for function {} must be a number", std::string(argument_names[i]), getName()); } } @@ -322,7 +322,7 @@ public: const auto& fraction_argument = arguments[argument_names.size()]; if (!isNumber(fraction_argument.type)) throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Argument 'fraction' for function {} must be number", getName()); + "Argument 'fraction' for function {} must be a number", getName()); } /// Optional precision argument diff --git a/src/Functions/throwIf.cpp b/src/Functions/throwIf.cpp index bda8426150e..91cb00bae51 100644 --- a/src/Functions/throwIf.cpp +++ b/src/Functions/throwIf.cpp @@ -26,22 +26,16 @@ class FunctionThrowIf : public IFunction { public: static constexpr auto name = "throwIf"; + static FunctionPtr create(ContextPtr) { return std::make_shared(); } - String getName() const override - { - return name; - } - + String getName() const override { return name; } bool isVariadic() const override { return true; } bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; } - size_t getNumberOfArguments() const override - { - return 0; - } + size_t getNumberOfArguments() const override { return 0; } DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { @@ -55,12 +49,13 @@ public: if (!isNativeNumber(arguments[0])) throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Argument for function {} must be number", - getName()); + "First argument of function {} must be a number (passed: {})", + getName(), + arguments[0]->getName()); if (number_of_arguments > 1 && !isString(arguments[1])) throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument of function {}", + "Second argument of function {} must be a string (passed: {})", arguments[1]->getName(), getName()); @@ -86,9 +81,7 @@ public: { const auto * message_column = checkAndGetColumnConst(arguments[1].column.get()); if (!message_column) - throw Exception(ErrorCodes::ILLEGAL_COLUMN, - "Second argument for function {} must be constant String", - getName()); + throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Second argument for function {} must be constant String", getName()); custom_message = message_column->getValue(); } @@ -108,12 +101,13 @@ public: || (res = execute(in, custom_message)) || (res = execute(in, custom_message)))) { - throw Exception{"Illegal column " + in->getName() + " of first argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN}; + throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of first argument of function {}", in->getName(), getName()); } return res; } +private: template ColumnPtr execute(const IColumn * in_untyped, const std::optional & message) const { @@ -128,7 +122,7 @@ public: if (!memoryIsZero(in_data.data(), 0, in_data.size() * sizeof(in_data[0]))) { throw Exception(ErrorCodes::FUNCTION_THROW_IF_VALUE_IS_NON_ZERO, - message.value_or("Value passed to '" + getName() + "' function is non zero")); + message.value_or("Value passed to '" + getName() + "' function is non-zero")); } size_t result_size = in_untyped->size(); diff --git a/tests/queries/0_stateless/00602_throw_if.sh b/tests/queries/0_stateless/00602_throw_if.sh index 1e8850028c4..d4c528a6da4 100755 --- a/tests/queries/0_stateless/00602_throw_if.sh +++ b/tests/queries/0_stateless/00602_throw_if.sh @@ -4,7 +4,7 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=../shell_config.sh . "$CURDIR"/../shell_config.sh -default_exception_message="Value passed to 'throwIf' function is non zero" +default_exception_message="Value passed to 'throwIf' function is non-zero" custom_exception_message="Number equals 1000000" ${CLICKHOUSE_CLIENT} --server_logs_file /dev/null --query="SELECT throwIf(number = 1000000) FROM system.numbers" 2>&1 | grep -cF "$default_exception_message" diff --git a/tests/queries/0_stateless/00995_exception_while_insert.sh b/tests/queries/0_stateless/00995_exception_while_insert.sh index 28351078df3..e0cd264a2b7 100755 --- a/tests/queries/0_stateless/00995_exception_while_insert.sh +++ b/tests/queries/0_stateless/00995_exception_while_insert.sh @@ -10,6 +10,6 @@ $CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS check;" $CLICKHOUSE_CLIENT --query="CREATE TABLE check (x UInt64, y UInt64 DEFAULT throwIf(x > 1500000)) ENGINE = Memory;" -seq 1 2000000 | $CLICKHOUSE_CLIENT --query="INSERT INTO check(x) FORMAT TSV" 2>&1 | grep -q "Value passed to 'throwIf' function is non zero." && echo 'OK' || echo 'FAIL' ||: +seq 1 2000000 | $CLICKHOUSE_CLIENT --query="INSERT INTO check(x) FORMAT TSV" 2>&1 | grep -q "Value passed to 'throwIf' function is non-zero." && echo 'OK' || echo 'FAIL' ||: $CLICKHOUSE_CLIENT --query="DROP TABLE check;"